Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit ded24df

Browse files
committed
Product Query: Add support for sorting by rating
1 parent 773b395 commit ded24df

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

assets/js/blocks/product-query/inspector-controls/popular-presets.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const PRESETS = [
1616
key: 'popularity/desc',
1717
name: __( 'Best Selling', 'woo-gutenberg-products-block' ),
1818
},
19+
{
20+
key: 'rating/desc',
21+
name: __( 'Top Rated', 'woo-gutenberg-products-block' ),
22+
},
1923
];
2024

2125
export function PopularPresets( props: ProductQueryBlock ) {

src/BlockTypes/ProductQuery.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ProductQuery extends AbstractBlock {
2828
*
2929
* @var array
3030
*/
31-
protected $custom_order_opts = array( 'popularity' );
31+
protected $custom_order_opts = array( 'popularity', 'rating' );
3232

3333
/**
3434
* All the query args related to the filter by attributes block.
@@ -238,6 +238,7 @@ private function get_custom_orderby_query( $orderby ) {
238238

239239
$meta_keys = array(
240240
'popularity' => 'total_sales',
241+
'rating' => '_wc_average_rating',
241242
);
242243

243244
return array(

0 commit comments

Comments
 (0)