How can I filter products by meta in Woocommerce REST API?

Question

I want filter products by meta_data in woocommerce rest api. I tried this, but not working:

$data = array(
                'numberposts'   => -1,
                'post_type'     => 'product',
                'meta_query' => array(
                    'relation'      => 'AND',
                    array(
                        'key'       => 'package_type',
                        'value'     => $filters['ad_type'],
                        'compare'   => '='
                    ),
                    array(
                        'key'       => 'package_location',
                        'value'     => $filters['ad_location'],
                        'compare'   => '='
                    ),
                    array(
                        'key'       => 'package_price_range',
                        'value'     => $filters['ad_price_range'],
                        'compare'   => '='
                    )
                )
            );

$_results = $this->woocommerce->get('products', $data);

It seems the $data filter is not prevail, it will get back the all product without filter. So the questions is, how can i use meta filters in api request?

0
, , wpdaniel 1 year 2020-07-21T05:10:23-05:00 0 Answers 74 views 1

Leave an answer

Browse
Browse