wordpress - 默认产品简短描述
问题描述
在我的 woocommerce 网站上,我想将文本“仅在商店中可用”添加到我所有产品的简短描述中,并且对于我添加的所有未来产品也默认使用相同的文本。
我进行了搜索,但解决方案对我来说似乎很复杂。是否有一些代码可以粘贴到functions.php 中?
谢谢!
解决方案
您可以轻松解决此问题。您需要将一些代码推送到主题 functions.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);