php - 为空描述显示 Woocommerce 产品页面默认描述
问题描述
是否可以在后端产品描述区域中为所有新添加的产品页面添加 Woocommerce 产品默认描述作为默认文本(例如免费)或默认功能,该功能将生成特定操作但仅适用于没有的产品t 有产品描述值
所需要的只是让描述在下面的描述中为新添加的产品具有默认的附加值
有人可以帮忙吗?
我发现这对产品的简短描述起到了神奇的作用,但我希望它是产品描述本身
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;
}
}
解决方案
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' );
像上面这样的东西应该可以工作。
推荐阅读
- java - 将请求路径参数绑定到对象
- javascript - 如何在html中呈现多行字符串变量
- ios - 通过 safari 检查 PWA 是否添加到主屏幕
- raster - 将点与不同投影中的栅格匹配
- javascript - 需要帮助设置节点 / Knex 的迁移
- git - 找不到 Github git-upload-pack 命令。找不到远程存储库
- google-apps-script - 扩展作为“用户访问应用程序”运行的 GAS Web 应用程序
- c# - DataReader 进入 WPF TextBox 与 RichTextBox
- javascript - 保存/恢复列状态时按 GroupBy 自动列对 agGrid 进行排序
- r - 在 ggplot2 中制作多个方面