在我的 woocommerce 網站上,我想在我所有產品的簡短描述中添加文本“僅在商店中可用”,并且對于我添加的所有未來產品,也將默認使用相同的文本。
我進行了搜索,但解決方案對我來說似乎很復雜。是否有一些代碼可以粘貼到functions.php 中?
謝謝!
uj5u.com熱心網友回復:
您可以輕松解決此問題。您需要將一些代碼推送到主題 functions.php 或使用代碼片段插件。此代碼僅在 WooCommerce 產品簡短描述為空時有效。
function wp_woocommerce_short_description_if_empty(){
global $post;
if (empty($post->post_excerpt)) {
$post_excerpt = '<p >';
$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);
uj5u.com熱心網友回復:
您也可以為默認產品描述嘗試此操作,您可以在產品簡短描述之前/之后添加自定義文本
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 >
<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 >
<li>'.__('Only available in stores').'</li>
</ul>';
return $post_excerpt;
}
注意:在產品頁面上的產品簡短描述之前添加自定義文本 - 代碼已注釋,因此您可以相應地取消注釋。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/323221.html
