是否可以为后端产品描述区域中所有新添加的产品页面添加Woocommerce产品默认描述,例如,作为默认文本(免费)或默认函数,该函数将生成特定的操作,但仅适用于没有产品描述值的产品
所需要的就是在下面的描述中获得新添加的产品的默认附加值。

有人能帮忙吗?
我发现除了产品的简短描述之外,它还具有魔力,但我希望它能够实现产品描述本身。
add_action( 'woocommerce_single_product_summary', 'bbloomer_echo_short_desc_if_empty', 21 );
function bbloomer_echo_short_desc_if_empty() {
global $post;
if ( empty ( $post->post_excerpt ) ) {
$post_excerpt = '<p class="default-short-desc">';
$post_excerpt .= 'This is the default, global, short description.<br>It will show if <b>no short description has been entered!</b>';
$post_excerpt .= '</p>';
echo $post_excerpt;
}
}发布于 2019-12-18 11:21:22
function woocommerce_default_description($content) {
$empty = empty($content) || trim($content) === '';
if(is_product() && $empty) {
$content = 'default text content';
}
return $content;
}
add_filter( 'the_content', 'woocommerce_default_description' );
function rmg_woocommerce_default_product_tabs($tabs) {
if (empty($tabs['description'])) {
$tabs['description'] = array(
'title' => __( 'Description', 'woocommerce' ),
'priority' => 10,
'callback' => 'woocommerce_product_description_tab',
);
}
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'rmg_woocommerce_default_product_tabs' );上面这样的东西应该管用。
发布于 2019-12-18 11:34:31
试试这个:
add_action( 'woocommerce_single_product_summary', 'bbloomer_echo_desc_if_empty', 21 );
function bbloomer_echo_desc_if_empty() {
global $post;
if ( empty ( $post->post_content ) ) {
$post_description = '<p class="default-content">';
$post_description .= 'This is the default, global, description.<br>It will show if <b>description has been entered!</b>';
$post_description .= '</p>';
echo $post_description;
}
}https://stackoverflow.com/questions/59390626
复制相似问题