我想在产品选项之前立即在Woo Commerce的产品简短描述下添加一些全局文本.
我可以直接更改文件,但当然一旦更新它就会重写.
还有另一种方法吗?
解决方法:
更新2:使用钩子有3种不同的方式:
1)在简短描述内容的末尾添加自定义文本(不适用于可变产品):
add_filter( 'woocommerce_short_description', 'add_text_after_excerpt_single_product', 20, 1 );
function add_text_after_excerpt_single_product( $post_excerpt ){
if ( ! $short_description )
return;
// Your custom text
$post_excerpt .= '<ul class="fancy-bullet-points red">
<li>Current Delivery Times: Pink Equine - 4 - 6 Weeks, all other products 4 Weeks</li>
</ul>';
return $post_excerpt;
}
Important – For variable products:
I found that there is bug like in When using the filterwoocommerce_short_description
that is apparently also active for the product variation description, and it should not (as this is not documented in developers documentation)… The solution is below:
2)在简短描述内容的末尾添加自定义文本,适用于所有产品类型:
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 )
return;
// The custom text
$custom_text = '<ul class="fancy-bullet-points red">
<li>Current Delivery Times: Pink Equine - 4 - 6 Weeks, all other products 4 Weeks</li>
</ul>';
?>
<div class="woocommerce-product-details__short-description">
<?PHP echo $short_description . $custom_text; // WPCS: XSS ok. ?>
</div>
<?PHP
}
add_action( 'woocommerce_before_single_product', 'add_text_after_excerpt_single_product', 25 );
function add_text_after_excerpt_single_product(){
global $product;
// Output your custom text
echo '<ul class="fancy-bullet-points red">
<li>Current Delivery Times: Pink Equine - 4 - 6 Weeks, all other products 4 Weeks</li>
</ul>';
}
代码位于活动子主题(或活动主题)的function.PHP文件中.经过测试和工作.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。