S
S
Sergey2018-02-28 10:02:26
WordPress
Sergey, 2018-02-28 10:02:26

Select all discounted products and only in stock?

There was a task to make a page "Promotions and discounts" in our online store, which would display goods only at a discount and only in stock. The left column should display a menu of product categories and only those categories that are discounted and in stock. Those. if there are discounted products in the "Diapers" category, but these products are not available, then the item of this category in the menu should not be displayed.
At the moment, the menu includes categories containing discounted products, but even if these products are not available.
Here is this page Promotions
I'm trying to do this:

$product_ids_on_sale = wc_get_product_ids_on_sale();
                            $args = array(
                                  'post_type' => 'product',
                                  'post_status '   => 'publish',
                                  'product_cat' => $slug,
                                  'post__in' => array_merge( array( 0 ), $product_ids_on_sale ),
                                  'meta_query' => array('relation' => 'AND',
                                        array(
                                            'key'     => 'availability_in_the_warehouse_1',
                                            'value'   => '0',
                                            'compare' => '>'
                                        ))
                                  );
                                $loop = new WP_Query( $args );

But all the products with a discount are still selected, even if there are none.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Drobyshev, 2018-02-28
@antoshadrobyshev

I don't know what kind of selection you have in the meta query.
To exclude products in 0 balance the meta query should be like this

'meta_query' => array(
        array(
            'key' => '_stock_status',
            'value' => 'instock'
        )

S
Sergey, 2020-11-19
@sslion

In fact, in my first post there is indeed an error in the filter, there is a filter by company to counterparty = project ID, which is an error. I put the ID of an existing company, and transactions with this company began to be displayed.
But I need a filter by project. The field UF_CRM_1599206263
'INTERNAL_FILTER' => array('UF_CRM_1599206263' => $this->entityID)
is responsible for this
. ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question