2017-03-17 76 views

回答

1

有做到這一點的幾種方法,但是我覺得最簡單的一種是使用類似如下:

<?php 

$term_count = wp_count_terms('pa_brand'); 

echo sprintf('We have products from %d different brands', $term_count); 

?> 

brandpa_brand是WooCommerce的蛞蝓屬性要計數。這是有效的,因爲WooCommerce爲每個產品屬性創建一個名稱前綴爲pa_的自定義分類。

當您在留言中提到你希望得到的product_tag分類計數,所以你能做到這一點使用:

<?php 

$term_count = wp_count_terms('product_tag'); 

echo sprintf('We have products from %d different brands', $term_count); 

?> 
+0

簡單,很好的答案,而且還包括了'wp_count_terms的鏈接( )'作爲進一步參考。 –

+0

非常感謝。如何找出WooCommerce使用哪些產品標籤? – digitalmads

+0

進入**產品 - >屬性**,並在表格中有一個** slug **列,用它來識別您希望使用的slu g。 – Kodaloid

相關問題