I am trying to do a conditional function to remove the Product Sorting when a product search results in no products found. I have modified the no-products-found.php to include a section on popular products, but I don't want the option to sort to be there (looks strange on mobile).
I tried the following code in functions.php, but to no success. The product sorting menu is removed on archive pages as well (so I don't think the if statement is correct). Can you please help me?
Hello,
I am trying to do a conditional function to remove the Product Sorting when a product search results in no products found. I have modified the no-products-found.php to include a section on popular products, but I don't want the option to sort to be there (looks strange on mobile).
I tried the following code in functions.php, but to no success. The product sorting menu is removed on archive pages as well (so I don't think the if statement is correct). Can you please help me?
function hide_sorting_if_search_zero ($displaystate) {
if(!woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) )
$displaystate = false;
return $displaystate;
}
add_filter( 'lab_wc_show_product_sorting', 'hide_sorting_if_search_zero' );
Thanks
Martin
Think I solved it with:
function hide_sorting_if_search_zero ($displaystate) {
if( !have_posts() )
$displaystate = false;
return $displaystate;
}
add_filter( 'lab_wc_show_product_sorting', 'hide_sorting_if_search_zero' );
Hi Martin,
We're glad to hear that
Will set this ticket as solved from here.