在單個產品模板中,條件is_product_category()不適用於您。正確的條件是兩個組合在這種情況下:
if (is_product() && has_term('categoryname', 'product_cat')) {
// display my customized field
}
....
它看起來像你試圖重寫content-single-product.php
模板。
移動woocommerce_single_product_summary
鉤子上ELSE語句中不是一個好主意,只要你不想顯示'categoryname'
產品有3上鉤功能:
* @hooked woocommerce_output_product_data_tabs - 10
* @hooked woocommerce_upsell_display - 15
* @hooked woocommerce_output_related_products - 20
相反(覆蓋的模板在這裏)你可以嵌入你的代碼(在你的活動兒童主題或主題的function.php文件中)使用更方便的2個鉤子:
//In hook 'woocommerce_single_product_summary' with priority up to 50.
add_action('woocommerce_single_product_summary', 'displaying_my_customized_field', 100);
function displaying_my_customized_field($woocommerce_template_single_title, $int) {
if (is_product() && has_term('categoryname', 'product_cat')) {
// echoing my customized field
}
};
OR
// In hook 'woocommerce_after_single_product_summary' with priority less than 10
add_action('woocommerce_after_single_product_summary', 'displaying_my_customized_field', 5);
function displaying_my_customized_field($woocommerce_template_single_title, $int) {
if (is_product() && has_term('categoryname', 'product_cat')) {
// echoing my customized field
}
};
非常感謝你。覆蓋content-single-product.php爲我工作。再次感謝。 –