【问题标题】:To get total added product quantity WooCommerce WordPress获得总添加产品数量 WooCommerce WordPress
【发布时间】:2016-02-03 18:07:20
【问题描述】:

我需要找出 WordPress WooCommerce 中添加产品的总量。我怎样才能得到它?

【问题讨论】:

标签: php wordpress woocommerce


【解决方案1】:

通过以下代码可以获取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;  

【讨论】:

    猜你喜欢
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多