【发布时间】:2015-06-28 18:04:03
【问题描述】:
我在 woocommerce 的帖子中使用 php,并希望根据其库存水平显示/隐藏类别中的产品。当前使用 get_term() 并且产品计数包括“缺货”产品。使用 get_terms() 并且同一类别的产品计数仅计算“库存”产品。如何编写 if else 条件语句以使用特定产品类别的 get_terms 计数?
这是我到目前为止的代码(“如果”在此类别中的产品“缺货”时为真。希望“如果”仅在此类别中的产品“有货”时为真"):
<?php
$term = get_term(373, 'product_cat' );
$category = $term->name;
$theCount = $term->count;
if ( ( $category = 'Outlet Other' ) && ( $theCount > 0 ) ){
echo '[product_category category="outlet-other" per_page="100" orderby="menu_order" order="asc"]';}
else {
echo 'There are currently no products in this category. Please check back soon!';}
?>
这是我在页面上用于测试目的的其他代码,它使用 get_terms() 显示此类别的产品计数等于“库存”数量:
<?php
$terms = get_terms( 'product_cat' );
foreach( $terms as $term ){
echo 'Product Category: ' . $term->name . ' - Count: ' . $term->count . "\r\n";}
?>
【问题讨论】:
标签: php wordpress woocommerce