woocommerce_catalog_orderbyfilter-hookWC 9.7.0

Allows you to change product sorting options on shop pages.

Usage

add_filter( 'woocommerce_catalog_orderby', 'wp_kama_woocommerce_catalog_orderby_filter' );

/**
 * Function for `woocommerce_catalog_orderby` filter-hook.
 * 
 * @param array $catalog_orderby_options Array of catalog orderby options.
 *
 * @return array
 */
function wp_kama_woocommerce_catalog_orderby_filter( $catalog_orderby_options ){
	// filter...
	return $catalog_orderby_options;
}
$array(array) (required)

An array of sorting options. Default sorting options:

array(
	'menu_order' => __( 'Default sorting', 'woocommerce' ),
	'popularity' => __( 'Sort by popularity', 'woocommerce' ),
	'rating'     => __( 'Sort by average rating', 'woocommerce' ),
	'date'       => __( 'Sort by latest', 'woocommerce' ),
	'price'      => __( 'Sort by price: low to high', 'woocommerce' ),
	'price-desc' => __( 'Sort by price: high to low', 'woocommerce' ),
)

Examples

#1 Remove sorting by date

add_filter( 'woocommerce_catalog_orderby', 'remove_default_sort_by_date' );

function remove_default_sort_by_date( $array ){
	unset( $array['date'] );

	return $array;
}

#2 Add a custom sorting option

add_filter( 'woocommerce_catalog_orderby', 'add_sorting_by_random' );

function add_sorting_by_random( $array ){
	$array['random'] = __( 'Random', 'woocommerce' );

	return $array;
}

For a complete example of adding sorting by a custom field, follow this link.

Changelog

Since 9.7.0 Introduced.

Where the hook is called

woocommerce_catalog_ordering()
woocommerce_catalog_orderby
woocommerce/includes/wc-template-functions.php 1689-1699
$catalog_orderby_options = apply_filters(
	'woocommerce_catalog_orderby',
	array(
		'menu_order' => __( 'Default', 'woocommerce' ),
		'popularity' => __( 'Popularity', 'woocommerce' ),
		'rating'     => __( 'Average rating', 'woocommerce' ),
		'date'       => __( 'Latest', 'woocommerce' ),
		'price'      => __( 'Price: low to high', 'woocommerce' ),
		'price-desc' => __( 'Price: high to low', 'woocommerce' ),
	)
);
woocommerce/includes/wc-template-functions.php 1702-1712
$catalog_orderby_options = apply_filters(
	'woocommerce_catalog_orderby',
	array(
		'menu_order' => __( 'Default sorting', 'woocommerce' ),
		'popularity' => __( 'Sort by popularity', 'woocommerce' ),
		'rating'     => __( 'Sort by average rating', 'woocommerce' ),
		'date'       => __( 'Sort by latest', 'woocommerce' ),
		'price'      => __( 'Sort by price: low to high', 'woocommerce' ),
		'price-desc' => __( 'Sort by price: high to low', 'woocommerce' ),
	)
);

Where the hook is used in WooCommerce

Usage not found.