我试图显示一个新订单中所有类别的简单列表,以及该类别中订单中的项目数量。因此,一些沿着:
喷雾罐- 3个附件- 2个标记- 5个等
这是我到目前为止尝试过的,但显然它只是显示了该类别中的产品总数,而不仅仅是与此订单有关。
foreach( $order->get_items() as $items ) {
$terms = wp_get_post_terms( $items->get_product_id(), 'product_cat' );
foreach( $terms as $term ) {
echo '<li>';
echo $term->name;
echo ' - ';
echo $term->count;
echo '</li>';
echo $term = count( $order->get_items() );
}
}
2条答案
按热度按时间fdx2calv1#
以下将列出WC订单中的产品类别,以及每个类别的数量,最后您将获得订单项目的数量:
测试和作品。
zf9nrax12#
这是最后的代码,我工作,如果有人需要它。