Remove the Default Sorting Options You Do Not Need in WooCommerce

WooCommerce gives us several product sorting options. Some of them are very useful, such as sorting by price, date, or popularity. However, there are also sorting methods that a site may not use at all. For example, if the store does not use ratings, then every option related to sorting by rating becomes unnecessary. To avoid confusing customers, it makes sense to remove those options.

Remove a specific sorting method from the front-end sorting options

# Remove "Sort by average rating" from the shop sorting dropdown
function wizhi_remove_default_sorting_option( $catalog_orderby_options ) {
    unset( $catalog_orderby_options['rating'] );
    return $catalog_orderby_options;
}
add_filter( 'woocommerce_catalog_orderby', 'wizhi_remove_default_sorting_option' );

The default WooCommerce sorting methods can be found in the WooCommerce source code related to catalog ordering, as shown below:

# Default WooCommerce sorting options
array(
    'menu_order' => __( 'Default sorting', 'woocommerce' ),
    'popularity' => __( 'Sort by popularity', 'woocommerce' ),
    'rating'     => __( 'Sort by average rating', 'woocommerce' ),
    'date'       => __( 'Sort by newness', 'woocommerce' ),
    'price'      => __( 'Sort by price: low to high', 'woocommerce' ),
    'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
)

Remove whichever option you do not want with unset(). Once you do that, the “Sort by average rating” option will disappear from the product sorting dropdown on the storefront. But there is still a rating-based option in the WooCommerce admin settings for the default sorting method, so we need to remove that one as well.

Remove a specific sorting method from the default sorting setting in the admin area

# Remove the rating-based sorting option from admin settings
function wizhi_remove_default_sorting_from_settings( $options ) {
    unset( $options['menu_order'] );
    return $options;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'wizhi_remove_default_sorting_from_settings' );

After this step, that sorting option is gone completely. Of course, in addition to removing sorting choices, we can also add our own custom options, but that is a topic for another article.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *