【发布时间】:2014-03-21 17:51:46
【问题描述】:
如何查看同一父类别的多个产品的多个产品的库存 以干燥的方式?我需要获取总库存和/或检查任何给定产品的库存是否不低于某个阈值。
到目前为止,我知道如何检索每个单独产品的库存,我需要 (1) 返回库存总量的值,以及 (2) 检查是否没有单独的值低于某个阈值。
这是我的代码:
<?php
$args = array(
'post_type' => 'product',
'product_cat' => 'name_of_my_category',
'orderby' =>'date',
'order' => 'DESC',
);
$name_of_my_query = new WP_Query( $args );
if ($name_of_my_query->have_posts()) :
while ($name_of_my_query->have_posts()) :
$name_of_my_query->the_post();
$product = get_product( $name_of_my_query->post->ID );
echo $product->stock;
endwhile;
endif;
wp_reset_query();
?>
在这个阶段,我只能想到对每个产品重复此代码,将返回的每个值分配给不同的变量并总结它们……相当漫长的过程,我确定一定有更简单的方法吗?
感谢您的帮助!
【问题讨论】: