将此代码放入函数中。如果类别slug与此实例中的“jackets”匹配,它将输出一个链接。
add_action( 'woocommerce_before_add_to_cart_button', 'content_before_addtocart_button' );
function content_before_addtocart_button() {
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
if( $term->slug === 'jackets')
echo '<div class="content-section">add custom size <a href="' . esc_url( get_term_link( $term->term_id, 'product_cat' ) ) . '">' . $term->name . '</a></div>';
}
}