• Resolved davide90

    (@davide90)


    Hello,

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

    Example:

     $cats = get_terms( ['taxonomy' => 'product_cat', 'parent' => 0] );
    
    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);
    
                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 4 products for categories, but i don’t see the single variations, example my hoodie green and my hoodie blue.

    What do you suggest to do ?

    Thank you

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @davide90

    Unfortunately, WooCommerce, by default, doesn’t list product variations separately on the shop page. Variations are shown on the individual product page.

    However, you can achieve this with the help of a plugin or custom code. The WooCommerce Show Single Variations plugin is one such plugin that can help you display your variations on the shop page and category pages and filter them just like you would simple products.

    If you prefer a coding approach, you’ll need to write a custom function to loop through each product and then through each variation of the product and display them. This will require a good understanding of WooCommerce’s structure and PHP programming.

    Just so you know, our support staff, including myself, are not developers who could help create custom code according to our Support Policy related to customizations. Therefore, if you need help with custom development tasks, we recommend contacting one of our official development partners called Codeable.io or asking development questions on the #developers channel of the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question.

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

    Thanks!

    Thread Starter davide90

    (@davide90)

    ok thank you !

    Hi @davide90

    ok thank you!

    You’re welcome! I’m glad to hear that the information provided was helpful.

    I’ll go ahead and mark this thread as resolved. However, if you ever have more questions or issues in the future, don’t hesitate to kick off a new topic.

    Hope you have a fantastic day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Variations products on shop page’ is closed to new replies.