Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取WordPress中的产品总添加量_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 获取WordPress中的产品总添加量

Php 获取WordPress中的产品总添加量,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我需要了解WordPress WooCommerce中添加产品的总量。如何获取它?通过以下代码,您可以获取woo commerce中的产品数量 在theme function.php文件中添加此函数 function get_productcount() { $product_count = 0; // loop through all categories to collect the count. foreach (get_terms('product_cat') as $t

我需要了解WordPress WooCommerce中添加产品的总量。如何获取它?

通过以下代码,您可以获取woo commerce中的产品数量

在theme 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;