-
AuthorPosts
-
May 2, 2024 at 5:11 pm #1441941
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 IDadd:
categoriesThank you
May 3, 2024 at 1:56 pm #1442168been searching for a solution to that but nothing yet. any idea if this is possible? thanks
May 4, 2024 at 2:42 am #1442248Hi,
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,
MikeMay 4, 2024 at 4:08 pm #1442294Thank 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?May 5, 2024 at 12:49 am #1442311Hi,
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 filteradd_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 -
AuthorPosts
- You must be logged in to reply to this topic.