[英]To get total added product quantity WooCommerce WordPress
I need to find out the total quantity of added products in WordPress WooCommerce. 我需要找出WordPress WooCommerce中添加的产品总数。 How can I get it?
我怎么才能得到它?
By Following code you can get the number of product quantity in woo-commerce. 通过下面的代码,您可以获得woo-commerce中产品数量的数量。
Add this function in your theme function.php file 将此功能添加到主题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;
} }
Now from your any theme page you can call this function. 现在,您可以从任何主题页面调用此功能。 In my example I added following line of code in header.php as,
在我的示例中,我在header.php中添加了以下代码行,
<?php echo your_product_count() ?>
Or In Other way you can directly add in your template 或者以其他方式,您可以直接添加模板
$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.