在woocommerce上特定目录的单个产品简短描述下添加文本 [英] Adding text under Single Product Short Description of a specific catalog on woocommerce
问题描述
我有 2 个目录
- 目录 1:3D 弹出式卡片.Slug:3d-pop-up-cards
- 目录 2:手机保护套.Slug:手机壳
我想在目录 1 的单一产品简短描述下添加文本(3d 立体卡片).我使用此代码,但我要添加的文本出现在两个目录中.对这个问题有任何想法请!我在这里添加的代码:
add_action('woocommerce_single_product_summary', 'custom_single_product_summary', 2);函数 custom_single_product_summary(){全球 $product;
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );add_action('woocommerce_single_product_summary', 'custom_single_excerpt', 20);
}
函数custom_single_excerpt(){全球 $post, $product;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );if ((! $short_description ) && (has_term('3d-pop-up-cards', 'product_cat', $product->id )))返回;//自定义文本$custom_text = '<strong><span style="color: #ff0000;"><li>My Text Here</li></span></strong>
';?><div class="woocommerce-product-details__short-description"><?php echo $short_description .$custom_text;//WPCS: XSS 没问题.?>
<?php
}
你应该试试这个:
add_filter( 'woocommerce_short_description', 'woo_add_text_after_excerpt_single_product', 20, 1 );功能woo_add_text_after_excerpt_single_product($custom_text){//您的自定义文本$custom_text = '<li><strong><span style="color: #ff0000;">My Text Here</span></strong></li>
';返回 $custom_text;}
I have 2 catalog
- Catalog 1: 3d pop up cards. Slug:3d-pop-up-cards
- Catalog 2: Phone Covers. Slug: Phone-Covers
I want to adding text under Single Product Short Description of Catalog 1 (3d Pop up cards). I use this code but the text I want to add appear in both catalogs. Any idea of this problem pls! My Added code here:
add_action( 'woocommerce_single_product_summary', 'custom_single_product_summary', 2 ); function custom_single_product_summary(){ global $product;
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'custom_single_excerpt', 20 );
}
function custom_single_excerpt(){ global $post, $product;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
if (( ! $short_description ) && (has_term( '3d-pop-up-cards', 'product_cat', $product->id )))
return;
// The custom text
$custom_text = '<ul class="fancy-bullet-points red">
<strong><span style="color: #ff0000;"><li>My Text Here</li></span></strong>
</ul>';
?>
<div class="woocommerce-product-details__short-description">
<?php echo $short_description . $custom_text; // WPCS: XSS ok. ?>
</div>
<?php
}
Thanks everyone in advance for the help! enter image description here enter image description here
You should try this:
add_filter( 'woocommerce_short_description', 'woo_add_text_after_excerpt_single_product', 20, 1 );
function woo_add_text_after_excerpt_single_product( $custom_text ){
// Your custom text
$custom_text = '<ul class="fancy-bullet-points red">
<li><strong><span style="color: #ff0000;">My Text Here</span></strong></li>
</ul>';
return $custom_text;
}
这篇关于在woocommerce上特定目录的单个产品简短描述下添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!