Hide some product sorting option from the frontend in WooCommerce

if ( ! function_exists( 'wpcb_hide_sorting_option_from_frontend' ) ) {
    /**
     * wpcb_hide_sorting_option_from_frontend.
     *
     * @see https://wpcodebook.com/snippets/hide-some-product-sorting-option-from-the-frontend-in-woocommerce/
     */
    function wpcb_hide_sorting_option_from_frontend( $sorting_options ) {
        if ( isset( $sorting_options['popularity'] ) ) {
            // This will hide "Sort by popularity" option
            // All default WooCommerce sorting options: 'menu_order', 'popularity', 'rating', 'date', 'price', 'price-desc'
            unset( $sorting_options['popularity'] );
        }
        return $sorting_options;
    }
    add_filter( 'woocommerce_catalog_orderby', 'wpcb_hide_sorting_option_from_frontend', PHP_INT_MAX );
}

Leave a Comment