在Woocommerce中,我尝试使用不同的方式排除特定的产品类别,请参见以下代码:
function isa_before_add_to_cart_form() {
global $post;
$demoslug = $post->post_name;
$demourl = get_bloginfo('url').'/'.$demoslug.'-gratuito/';
$demotitle = esc_attr($post->post_title);
echo '<a href="'.$demourl.'" title="'.$demotitle.'" id="livedemo" class="button" target="_blank">testar</a>';
}
add_action('woocommerce_after_shop_loop_item','isa_before_add_to_cart_form');
add_action('woocommerce_after_add_to_cart_form','isa_before_add_to_cart_form');
但是我尝试过的那些都没有。
答案 0 :(得分:0)
您可以尝试使用has_term()
函数排除产品类别(其中clothing
是要排除的产品类别):
add_action('woocommerce_after_shop_loop_item', 'displayed_product_custom_button');
add_action('woocommerce_after_add_to_cart_form', 'displayed_product_custom_button');
function displayed_product_custom_button() {
global $post, product;
if( ! has_term( array('clothing'), 'product_cat' ) ) {
$demoslug = $post->post_name;
$demourl = get_bloginfo('url').'/'.$demoslug.'-gratuito/';
$demotitle = esc_attr($post->post_title);
echo '<a href="'.$demourl.'" title="'.$demotitle.'" id="livedemo" class="button" target="_blank">testar</a>';
}
}