你的问题不是很清楚。
1) 如果您想在该产品类别描述下方的产品类别存档页面上显示特定产品类别的自定义按钮,您将使用:
add_action( 'woocommerce_archive_description', 'extra_button_on_product_category_archives', 20 );
function extra_button_on_product_category_archives() {
if ( is_product_category('bracelets') ) {
echo '<a class="button" href="www.test.com">Extra Button</a>';
}
}
2) 如果您想在单个产品页面中为特定产品类别在此产品的简短描述下方显示自定义按钮,您将使用:
add_action( 'woocommerce_single_product_summary', 'extra_button_on_product_page', 22 );
function extra_button_on_product_page() {
global $post, $product;
if ( has_term( 'bracelets', 'product_cat' ) ) {
echo '<a class="button" href="www.test.com">Extra Button</a>';
}
}
3) 如果您想在该产品的描述(在产品选项卡中)下方的特定产品类别的单个产品页面中显示自定义按钮,您将使用:
add_filter( 'the_content', 'add_button_to_product_content', 20, 1 );
function add_button_to_product_content( $content ) {
global $post;
if ( is_product() && has_term( 'bracelets', 'product_cat' ) )
$content .= '<a class="button" href="www.test.com">Extra Button</a>';
// Returns the content.
return $content;
}
4) 如果您想在产品标签下方的特定产品类别的单个产品页面中显示自定义按钮,您将使用:
add_action( 'woocommerce_after_single_product_summary', 'extra_button_on_product_page', 12 );
function extra_button_on_product_page() {
global $post, $product;
if ( has_term( 'bracelets', 'product_cat' ) ) {
echo '<a class="button" href="www.test.com">Extra Button</a>';
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件中。
经过测试并且有效。
对于产品类别档案页面,请使用is_product_category()。
对于所有其他情况has_term()。