HI
I’d like to remove some “sort by” options from the shop page dropdown menu and add “sort by” categories.
remove:
custom
average rating
random
product ID
add:
categories
Thank you
been searching for a solution to that but nothing yet. any idea if this is possible? thanks
Hi,
To remove the items that you listed above Try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor:
function my_woocommerce_catalog_orderby( $orderby ) {
unset($orderby["menu_order"]);
unset($orderby["rating"]);
unset($orderby["rand"]);
unset($orderby["id"]);
return $orderby;
}
add_filter( "avf_wc_product_order_dropdown_frontend", "my_woocommerce_catalog_orderby", 20 );
the menu will then look like this:
but to add the category item you will need to use the WooCommerce Product Table plugin this is a paid plugin and I don’t know if it will work correctly with Enfold.
This is the article that says how to add categories to the options.
Best regards,
Mike
Thank you. removing sorting options with the PHP code worked well.
Will the WooCommerce Product Table plugin which also allows removal of sorting options conflict with the above removal code?
Hi,
Glad that this helped, I don’t think that it would conflict but I don’t know for sure and I can’t test, if you do try the plugin you can always keep this in mind as you test.
In my research and testing I found a working way to add a option “category” to the sort by filter
add_filter( 'avf_wc_product_order_dropdown_frontend', 'my_add_custom_sorting_options' );
function my_add_custom_sorting_options( $options ){
$options[ 'cat' ] = 'Category';
return $options;
}
but this doesn’t work because there doesn’t seem to be a built-in query to orderby categories, or at least I couldn’t find one. I assume that the plugin creates a query to do this.
Otherwise perhaps this will put you on the right track and you or your team can write a query for this, I was not able to.
Best regards,
Mike