Variations products on shop page
-
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 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Variations products on shop page’ is closed to new replies.