Skip to content

Instantly share code, notes, and snippets.

@grola
Last active January 28, 2018 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grola/f3f1b1c035ad2f68e43e09779a1bad17 to your computer and use it in GitHub Desktop.
Save grola/f3f1b1c035ad2f68e43e09779a1bad17 to your computer and use it in GitHub Desktop.
Remove WooCommerce sorting options
<?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