NO BUG: Sale products in query Loop

Browser: Chrome 117
OS: Windows

Hi bricks team,

I tried to display the sale product as shown below. But there are two important problems.
Screenshot

1- If Cache query loops are enabled in the settings, when we add and remove a product from the sale, there is a problem in displaying the product in the front end. When Cache query loops.

2- If we have a variable product and only one or more variables have a sale price, that product is not known as a sale product. But if we add the products element and activate the On sale option, the variable products will be known as sale products without any problem. Therefore, this problem exists only in the query loop.

1 Like

Hello,

Did you find a soution to display variable product on sale with a querry ?

Thanks

Hi, Unfortunately, I did not find a solution.

Hi @timmse, Would you please check this?

Hi Jolia,
Thanks so much for your report.

  1. this is the purpose of the object cache. If it is not cleared, it shows the cached data. If your products change frequently you should not use this option.

  2. we use a function provided by WooCommerce in the products element. If you use a custom loop, you are responsible for the correct query and due to the complexity of variable products, the simple orderby setting is not sufficient.

a) Add this to the query editor (without any other query settings)

return [
    'post_type' => array('product'),
    'posts_per_page' => -1,
    'orderby' => 'meta_value_num',
    'meta_key' => '_price',
    'order' => 'ASC',
    'post__in' => wc_get_product_ids_on_sale(),
];

We are already working on a simpler solution for the query loop to include on sale and featured products and hide out of stock products.

Best regards,
timmse

2 Likes

thank you @timmse,

It is really great that you are working on this feature. I think it would be great if you could add a new section to the query loop to have all the important queries and be easily selectable. Queries such as :

  • on sale

  • top sales

  • featured products

  • related (for posts and custom post types)

  • cross sells

  • up sells

  • recently viewed

And add the hide out of stock products option as a switcher button. That would be really great.

1 Like

Also a binary filter to apply on the loop query to filter by products “on sale”.