0

Not able to fetch variation sales product according to particular product category . My code fetch only simple products not variable products.

  $cat_id = $_GET['catid'];

  $args = array(    
'post_type'             => 'product',
'post_status'           => 'publish',
'posts_per_page'        =>-1, 
'meta_query'     => array(
    'relation' => 'OR',
  array( // Variable products type
        'key'           => '_min_variation_sale_price',
        'value'         => 0,
        'compare'       => '>',
        'type'          => 'numeric'
    ),
    array( // Simple products type   
        'key'           => '_sale_price',
        'value'         => 0,
        'compare'       => '>',
        'type'          => 'numeric'
    )
    ),
'tax_query'             => array(
    array(
        'taxonomy'      => 'product_cat',
        'field' => 'term_id', //This is optional, as it defaults to 'term_id'
        'terms'         => $cat_id,
        'include_children' => true,
        'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
    )
    )

);
$products = new WP_Query($args);
0

WooCommerce uses 'product_variation' as the post type for variable products.

So the top level for a variable product is post_type 'product', whereas each variation is post_type 'product_variation'.

Data associated with the particular variation is stored with the appropriate 'product_variation' post.

  • No effect, want sales products of simple and variable product for particular category.But when i am not using tax_query it shows both sales products. – tanu Jun 9 '18 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.