Instantly share code, notes, and snippets.

@grola /functions.php
Last active Jan 28, 2018

Embed
What would you like to do?
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