我正在使用将简短描述移动到Woocommerce单个产品页面的选项卡中来将WooCommCommerce产品的简短描述移动在自定义产品选项卡中。
不幸的是,当没有简短的描述时,我不知道如何取消设置自定义选项卡。
当WooCommerce产品的简短描述为空时,如何从自定义选项卡中隐藏?
如果产品简短描述为空,以下内容将隐藏此自定义选项卡:
// Add short description as a new custom product tab
add_filter( 'woocommerce_product_tabs', 'add_custom_product_tab' );
function add_custom_product_tab( $tabs ) {
global $post, $product;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
if ( ! empty($short_description) ) {
$tabs['short_description'] = array(
'title' => __( "What's in the box", "woocommerce" ),
'priority' => 200,
'callback' => 'short_description_tab_content'
);
}
return $tabs;
}
// Custom product tab content
function short_description_tab_content() {
global $post, $product;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
if ( ! empty($short_description) ) {
echo '<div class="woocommerce-product-details__short-description">' . $short_description . '</div>'; // WPCS: XSS ok.;
}
}
代码位于活动子主题(或活动主题(的functions.php文件中。测试并工作。