• Hello,

    i’m trying to query all my products together with products variations for each category i have. I want to have 4 products for category on shop page.

    I wrote this:

    ?foreach( $cats as ?$cat){
    
    ? ? ? ? $product_args = array( 
    
    ? ? ? ? ? ? 'posts_per_page' => 4,
    
    ? ? ? ? ? ? 'post_status' => array('publish'),
    
    ? ? ? ? ? ? 'post_type' => array('product', 'product_variation'),
    
    ? ? ? ? ? ? 'orderby' => 'ID',
    
    ? ? ? ? ? ? 'suppress_filters' => false,
    
    ? ? ? ? ? ? 'orderby' => 'title',
    
    ? ? ? ? ? );
    
    ? ? ? ? ? if (!empty($cats)) {
    
    ? ? ? ? ? ? $product_args['tax_query'] = array(
    
    ? ? ? ? ? ? ? ?array(
    
    ? ? ? ? ? ? ? ? ?'taxonomy' => 'product_cat',
    
    ? ? ? ? ? ? ? ? ?'field' => 'term_id',
    
    ? ? ? ? ? ? ? ? ?'terms' => array( $cat->term_id ),
    
    ? ? ? ? ? ? ? ? ?'operator' => 'IN',
    
    ? ? ? ? ? ? ));
    
    ? ? ? ? ? }
    
    ? ? ? ? ? $query = new WP_Query( $product_args);
    
    ? ? ? ? ? do_action( 'woocommerce_before_shop_loop' );
    
    ? ? ? ? ? ? woocommerce_product_loop_start();
    
    ? ? ? ? ? if ( wc_get_loop_prop( 'total' ) ) {
    
    ? ? ? ? ? ? while ( $query->have_posts() ) {
    
    ? ? ? ? ? ? ? ? $query->the_post();
    
    ? ? ? ? ? ? ? ? ?do_action( 'woocommerce_shop_loop' );
    
    ? ? ? ? ? ? ? ? wc_get_template_part( 'content', 'product' );
    
    ? ? ? ? ? ? }
    
    ? ? ? ? }
    
    ? ? ? ? wp_reset_postdata();
    
    ? ? ? ? woocommerce_product_loop_end();
    
    ? ? ? }

    With this i have correctly 4 products for category, but i still don’t see single variations, for example my blue and green hoodie.

    Can you help me ?

    Thank you

    The page I need help with: [log in to see the link]

  • The topic ‘Variations products category on shop page’ is closed to new replies.