【发布时间】:2021-06-08 02:50:58
【问题描述】:
使用 WooCommerce,我在下面的代码中遇到了问题:我尝试从循环中跳过特定类别。产品已被跳过,但一些剩余产品多次显示:
foreach ( $order->get_items() as $item_id => $item ) {
$product_id = $item->get_product_id();
$terms = get_the_terms( $product_id, 'product_cat' );
foreach ($terms as $term) {
if ($product_cat_id != 38355) { //category id
echo $name = $item->get_name().'<br>';
}
}
}
如何避免此循环中的项目名称重复?
【问题讨论】:
标签: php wordpress woocommerce orders taxonomy-terms