WoCoommerce: get bundle data items product in custom loop

836 views Asked by At

I have a pizza sales site which offers 'Ingredients' of which these are simple products, for example: Pizza Napolí is a bundle product, this product has ingredients grouped together.

What I'm looking for is to show in a custom loop (wp_query) the children products or ingredients of this pizza, which are 'Cheese(Queso)', 'Bacon(Tocineta)', etc.

Images reference here: DATA items DATA items

My code:

<?php 

    $args = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'ignore_sticky_posts' => 1,
    'orderby' => 'date',
    'order' => 'ASC',
    'meta_key' => '_stock_status',
    'posts_per_page' => 10,
    'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'terms' => array('pizzas'),
            'field' => 'name',
            'operator' => 'IN'
        )
    )
    );
    
// End query
$products = new WP_Query( $args, 'woocommerce'); ?>
<div class="menu-grid-pizzas">
    <?php if ($products->have_posts()): ?>
        <div class="container">
        <ul class="grid-pizzas-list">
            <?php while ($products->have_posts()): $products->the_post(); ?>
                <li class="grid-pizzas-content">
                        <div class="content-left">
                            <div class="grid-img">
                                <a href="<?php the_permalink();?>">
                                    <?php the_post_thumbnail('medium');?>
                                </a>
                            </div>
                        </div>
                        <div class="content-right">
                            <div class="grid-product-title">
                                <a href="<?php the_permalink();?>">
                                    <h4><?php the_title();?></h4>
                                </a>
                            </div>
                            <div class="grid-product-content">
                                <?php $content = get_the_content();?>
                                <p><?php echo mb_strimwidth($content, 0, 120, "...");?></p>
                            </div>
                            <div class="grid-product-ingredints">
                                    <!-- HERE get DATA items bundles -->
                            </div>
                            <div class="grid-product-price">
                                <?php $precio = get_post_meta( get_the_ID(), '_price', true );?>
                                <p><?php echo wc_price( $precio ); ?></p>
                            </div>
                            <div class="grid-product-add-to-card">
                                <?php do_action('woocommerce_after_shop_loop_item' , 'woocommerce_template_loop_add_to_cart' , 10 );?>
                            </div>
                        </div>
                </li>
            <?php endwhile;?>
            <?php wp_reset_postdata();?>
        </ul>
        </div>
        <?php endif;?>
</div>

As you can see, it is a custom loop from which I call all products with the category 'Pizza' with a wp_query.

I hope you can help me, thank you.

0

There are 0 answers