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

Best selling products block: show only products with sales and most sold first #10448

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/BlockTypes/ProductBestSellers.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class ProductBestSellers extends AbstractProductGrid {
* @param array $query_args Query args.
*/
protected function set_block_query_args( &$query_args ) {
$query_args['orderby'] = 'popularity';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the correct query for best selling product. I wonder why do you need to change it 🤔

$query_args['meta_key'] = 'total_sales'; // phpcs:ignore WordPress.DB.SlowDBQuery
$query_args['orderby'] = 'meta_value_num';
$query_args['order'] = 'DESC';
Comment on lines +22 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order query arguments will be later overridden by AbstractProductGrid::set_ordering_query_args(), which explains the Danny comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to remove the orderby attribute in the block.json file, we will need to reorder the call of set_ordering_query_args() in AbstractProductGrid so the query variables set by child classes won't be override by other methods in AbstractProductGrid.


$this->meta_query[] = array(
'key' => 'total_sales',
'value' => 0,
'compare' => '>',
);
}
}
Loading