Last active
January 28, 2018 14:53
-
-
Save grola/f3f1b1c035ad2f68e43e09779a1bad17 to your computer and use it in GitHub Desktop.
Remove WooCommerce sorting options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$studiowp_remove_orderby = array( 'rating', 'popularity', 'price', 'price-desc' ); | |
add_action( 'init', 'studiowp_init_orderby' ); | |
function studiowp_init_orderby() { | |
global $studiowp_remove_orderby; | |
if ( !is_admin() && isset( $_GET['orderby'] ) ) { | |
if ( in_array( $_GET['orderby'], $studiowp_remove_orderby ) ) { | |
wp_redirect( home_url() ); | |
exit; | |
} | |
} | |
} | |
add_filter( 'woocommerce_catalog_orderby', 'studiowp_woocommerce_catalog_orderby', 20 ); | |
function studiowp_woocommerce_catalog_orderby( $orderby ) { | |
global $studiowp_remove_orderby; | |
foreach ( $studiowp_remove_orderby as $value ) { | |
unset( $orderby[ $value ] ); | |
} | |
return $orderby; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment