Automattic\WooCommerce\Blocks\BlockTypes

ProductCollection::get_custom_orderby_query()privateWC 1.0

Return query params to support custom sort values

Method of the class: ProductCollection{}

No Hooks.

Return

Array.

Usage

// private - for code of main (parent) class only
$result = $this->get_custom_orderby_query( $orderby );
$orderby(string) (required)
Sort order option.

ProductCollection::get_custom_orderby_query() code WC 9.4.2

private function get_custom_orderby_query( $orderby ) {
	if ( ! in_array( $orderby, $this->custom_order_opts, true ) ) {
		return array( 'orderby' => $orderby );
	}

	$meta_keys = array(
		'popularity' => 'total_sales',
		'rating'     => '_wc_average_rating',
	);

	return array(
		// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
		'meta_key' => $meta_keys[ $orderby ],
		'orderby'  => 'meta_value_num',
	);
}