如果你想在個別商品頁面讀取奇商品類別分類 , 首先前往編輯佈景主題 , 編輯 function.php 檔案並新增以下代碼
add_shortcode('techmusea_productcategory', 'get_current_product_category');
function get_current_product_category(){
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
$nterms = get_the_terms( $post->ID, 'product_tag' );
foreach ($terms as $term ) {
$product_cat_id = $term->term_id;
$product_cat_name = $term->name;
break;
}
echo $product_cat_name;
}
新增後即代表您可以使用 shortcode 短代碼並可以新增到個別商品內容
[techmusea_productcategory]