wordpress - 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”的所有产品。
我希望你能帮助我,谢谢。
解决方案
推荐阅读
- sql - Hive - 为每行添加 2 列,其中包含一些空值
- c# - Excel 中的 JSON 重复输入部分
- matlab - 如何检查 2 个向量的相同元素,然后将不相似的元素附加到矩阵的末尾
- typescript - 如何在 Deno 中提取类型
- c++11 - STL 映射 - 没有匹配的构造函数
- python - AttributeError:模块“base64”没有属性“b64decode”
- tensorflow - 根据图形时间未知的大小拆分张量
- javascript - async/await 嵌套是否会对性能产生影响?
- c# - 如何将 C# 8 中的默认返回值标记为仅对类可以为空?
- jenkins - Jenkins 多分支:错误 MC1000:未知构建错误