woocommerce_default_catalog_orderby_options
Allows you to change the sorting options in the product catalog settings.
Usage
add_filter( 'woocommerce_default_catalog_orderby_options', 'wp_kama_woocommerce_default_catalog_orderby_options_filter' );
/**
* Function for `woocommerce_default_catalog_orderby_options` filter-hook.
*
* @param $array
*
* @return
*/
function wp_kama_woocommerce_default_catalog_orderby_options_filter( $array ){
// filter...
return $array;
}
- $value(array)
- An array of sorting parameters.
Examples
#1 Remove rating sorting from the settings
add_filter( 'woocommerce_default_catalog_orderby_options', 'remove_default_sort_by_rating' );
function remove_default_sort_by_rating( $array ){
unset( $array['rating'] );
return $array;
}
#2 Add a custom sorting option to the settings
For a complete example of adding sorting by a custom field, follow this link.
add_filter( 'woocommerce_default_catalog_orderby_options', 'add_sorting_by_sale' );
function add_sorting_by_sale( $array ){
$array['sale'] = __( 'Sale', 'woocommerce' );
return $array;
}
Where the hook is called
woocommerce_default_catalog_orderby_options
woocommerce_default_catalog_orderby_options
woocommerce/includes/customizer/class-wc-shop-customizer.php 325-335
$options = apply_filters( 'woocommerce_default_catalog_orderby_options', array( 'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ), 'popularity' => __( 'Popularity (sales)', 'woocommerce' ), 'rating' => __( 'Average rating', 'woocommerce' ), 'date' => __( 'Sort by most recent', 'woocommerce' ), 'price' => __( 'Sort by price (asc)', 'woocommerce' ), 'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ), ) );
woocommerce/includes/customizer/class-wc-shop-customizer.php 496-506
'choices' => apply_filters( 'woocommerce_default_catalog_orderby_options', array( 'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ), 'popularity' => __( 'Popularity (sales)', 'woocommerce' ), 'rating' => __( 'Average rating', 'woocommerce' ), 'date' => __( 'Sort by most recent', 'woocommerce' ), 'price' => __( 'Sort by price (asc)', 'woocommerce' ), 'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ), ) ),
