Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Include Atributes in search
- This topic has 20 replies, 2 voices, and was last updated 8 years, 11 months ago by
Ernest Marcinko.
-
AuthorPosts
-
June 7, 2017 at 1:29 pm #13408
fespigado
ParticipantSorry Ernest,
but still looking for products in stock 0 searches.I´ve add added 1 more condition but it does not work.
**********************************************************
add_filter( ‘asp_results’, ‘asp_stock_to_content’, 1, 1 );
function asp_stock_to_content( $results ) {
$custom_field = “_stock”;foreach ($results as $k=>$v) {
if ($v->content_type != “pagepost” || $v->post_type != “product”)
continue;
if ( function_exists(‘get_field’) )
$meta_value = get_field( $v->id, $custom_field, true ); // ACF support
else
$meta_value = get_post_meta( $v->id, $custom_field, true );
// Modify the post title to add the meta value
if ( !empty($meta_value) || $meta_value <=0)
$results[$k]->content .= ‘<br>Stock: ‘ . intval($meta_value) . ‘‘;
}return $results;
}June 7, 2017 at 2:02 pm #13411Ernest Marcinko
KeymasterHi,
Thank you very much for your offer and your kind words, I’m working alone so I’m completely overloaded with work for months. For WordPress related work I recommend wpkraken.io – it’s a fairly new service, by a team of codecanyon/themeforest authors, specialized in WordPress. In case you want to outsorce some customizations, they might worth asking.
As for the code
That code does no exclusions whatsoever, it’s only a visual ‘fix’ for rounding up the values. But, there is a way to check the stock status of the products (stored in a different custom field), and exclude them, check on this knowledge-base article: Showing in-stock products onlyJune 7, 2017 at 4:11 pm #13424fespigado
ParticipantHi,
sorry for my bad english.
What I mean is that the stock does not appear but the product should appear.June 7, 2017 at 4:17 pm #13426fespigado
ParticipantHi Ernest,
thanks for the information.
The project I’m talking about is not on the wordpress platform.
It’s an adhoc project.June 14, 2017 at 7:55 am #13554fespigado
ParticipantAs promised, I share the code to show the stock in the search results if it is greater than 0. thanks for your help
add_filter( ‘asp_results’, ‘asp_stock_to_content’, 1, 1 );
function asp_stock_to_content( $results ) {
$custom_field = “_stock”;foreach ($results as $k=>$v) {
if ($v->content_type != “pagepost” || $v->post_type != “product”)
continue;
if ( function_exists(‘get_field’) )
$meta_value = get_field( $v->id, $custom_field, true ); // ACF support
else
$meta_value = get_post_meta( $v->id, $custom_field, true );
// Modify the post title to add the meta valueif ( $meta_value > 0)
$results[$k]->content .= ‘<br>Stock: ‘ . intval($meta_value) . ‘‘;
else
continue;
}return $results;
}June 14, 2017 at 11:47 am #13577Ernest Marcinko
KeymasterHi!
Thank you very much!
I think I might have another solution as well, altough I’m not sure if it works in all cases. I have placed it into this knowledge base article: https://wp-dreams.com/knowledge-base/woocommerce-showing-products-in-stock-only/
..the difference is that his one will completely remove the products if not in stock from the results.
-
AuthorPosts
- You must be logged in to reply to this topic.