How to Remove the WooCommerce Default Sorting Option September 11 2014
Today’s Ask SkyVerge question comes from Loic:
I like your Product Sorting Options plugin! Is it possible to remove the default sorting in an easy way using this?
Removing the WooCommerce Default Sorting option on the shop and category pages is not part of our free plugin, but it’s easy enough to do using a tiny bit of code. Remember to add this code appropriately as per our How to add Custom Code tutorial!
The default sorting option is really handy to use as a customized display of your products – here’s a tutorial I wrote on creating custom WooCommerce product sorting for your shop on Sell with WP. However, some shop owners don’t want to use this at all – maybe you’re using our Extra Product Sorting Options plugin to add alphabetical sorting and you’ve set this as the default.
First, let’s remove this sorting option from the frontend of the site (the sorting dropdown on the “Shop” page). This dropdown is generated by an array of orderby options, so we simply have to unset the menu_order
item from the array. This will remove it from the dropdown so that customers can no longer select “Default Sorting” as a sorting option.
/** * Removes "Default Sorting" from the shop template */ function skyverge_remove_default_sorting_option( $catalog_orderby_options ) { unset( $catalog_orderby_options['menu_order'] ); return $catalog_orderby_options; } add_filter( 'woocommerce_catalog_orderby', 'skyverge_remove_default_sorting_option' );
Now this will not be displayed at all in the dropdown on the shop page. Whatever you’ve selected as the default option under WooCommerce > Settings > Products will be used for the default sorting instead, and all other options will be present in the dropdown.
You can use this snippet to remove other sorting options as well. Instead of unsetting menu_order
, you can unset the other keys found here to remove the other sorting options.
The above snippet will not get rid of the default sorting option in the admin, so you should select a different option as the default and save your settings.
If you’d like to remove “Default Sorting” from the admin as well, you can do something similar to the above snippet. Since this option is again added as part of an array of options, we can simply unset the menu_order
here as well:
/** * Removes "Default Sorting" option from the Product Settings */ function skyverge_remove_default_sorting_from_settings( $options ) { unset( $options['menu_order'] ); return $options; } add_filter( 'woocommerce_default_catalog_orderby_options', 'skyverge_remove_default_sorting_from_settings' );
Again, we could unset any of the sorting options found here using this snippet by replacing menu_order
with the appropriate key instead.
That’s it! The WooCommerce Default Sorting option will not be available to set as a default option, and it won’t be present on the shop pages as an option for customers to select.
Update: Not comfortable with the code? Here’s a plugin that will create a setting to do this for you: WooCommerce Remove Product Sorting.
The post How to Remove the WooCommerce Default Sorting Option appeared first on SkyVerge.