Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Include Atributes in search
This topic contains 20 replies, has 2 voices, and was last updated by Ernest Marcinko 6 years, 10 months ago.
- AuthorPosts
- June 7, 2017 at 1:29 pm #13408
Sorry 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;
}Attachments:
You must be logged in to view attached files.June 7, 2017 at 2:02 pm #13411Hi,
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
Best,
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 only
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
June 7, 2017 at 4:11 pm #13424Hi,
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 #13426Hi 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 #13554As 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 #13577Hi!
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.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.