首页 > 解决方案 > WoCoommerce:在自定义循环中获取捆绑数据项产品

问题描述

我有一个比萨销售网站,它提供“成分”,其中这些是简单的产品,例如:Pizza Napoli 是捆绑产品,该产品具有组合在一起的成分。

我正在寻找的是在自定义循环(wp_query)中显示这个披萨的儿童产品或成分,它们是“奶酪(Queso)”、“培根(Tocineta)”等。

图片参考这里: 数据项 数据项

我的代码:

<?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>

如您所见,它是一个自定义循环,我使用 wp_query 调用类别为“Pizza”的所有产品。

我希望你能帮助我,谢谢。

标签: wordpresswoocommercebundles

解决方案


推荐阅读