默认的产品简短描述



在我的woocommerce网站上,我想添加文字"Only available in stores"我的所有产品的简短描述,也有相同的文本默认为所有我未来添加的产品。

我进行了搜索,但解决方案似乎对我来说太复杂了。是否有一些代码可以粘贴到functions。php中?

谢谢!

这个问题很容易解决。您需要将一些代码推送到主题函数。php或使用代码片段插件。此代码仅在WooCommerce产品简短描述为空时有效。

function wp_woocommerce_short_description_if_empty(){
global $post;
if (empty($post->post_excerpt)) {
$post_excerpt = '<p class="default-short-desc">';
$post_excerpt .= 'Your Custom Message Here.';
$post_excerpt .= '</p>';
echo $post_excerpt;
}
}
add_action('woocommerce_single_product_summary', 'wp_woocommerce_short_description_if_empty', 21);

您也可以在默认的产品描述中尝试这样做,您可以在产品简短描述之前/之后添加自定义文本

add_filter( 'woocommerce_short_description', 'woo_add_text_after_excerpt_single_product', 20, 1 );
function woo_add_text_after_excerpt_single_product( $post_excerpt ){
/* Method 1: Add Custom Text before the Product Short Description on product page */
/* $content= '<ul class="fancy-bullet-points red">
<li>'.__('Only available in stores').'</li>
</ul>';
return $content.'<br>'.$post_excerpt; 
*/

/* Method 2: Add Custom Text after the Product Short Description on product page */
$post_excerpt .= '<ul class="fancy-bullet-points red">
<li>'.__('Only available in stores').'</li>
</ul>';
return $post_excerpt;
}

注意:在产品页面的产品简短描述之前添加自定义文本-代码被注释所以你可以取消相应的注释。

最新更新