![](/img/trans.png)
[英]Display product total and cart subtotal on quantity change in WooCommerce product page
[英]To get total added product quantity WooCommerce WordPress
我需要找出WordPress WooCommerce中添加的产品总数。 我怎么才能得到它?
通过下面的代码,您可以获得woo-commerce中产品数量的数量。
将此功能添加到主题function.php文件中
function get_productcount() {
$product_count = 0;
// loop through all categories to collect the count.
foreach (get_terms('product_cat') as $term)
$product_count += $term->count;
return $product_count;
}
现在,您可以从任何主题页面调用此功能。 在我的示例中,我在header.php中添加了以下代码行,
<?php echo your_product_count() ?>
或者以其他方式,您可以直接添加模板
$terms = get_terms( 'product_cat' );
foreach( $terms as $term )
{
$product_count += $term->count;
echo 'Product Category: '
. $term->name
. ' - Count: '
. $term->count;
}
echo "Total count:". $product_count;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.