Php 当其为空时隐藏WooCommerce产品简短描述自定义选项卡

Php 当其为空时隐藏WooCommerce产品简短描述自定义选项卡,php,wordpress,woocommerce,tabs,hook-woocommerce,Php,Wordpress,Woocommerce,Tabs,Hook Woocommerce,我正在使用移动自定义产品选项卡中的Woocommerce产品简短描述 不幸的是,当没有简短的描述时,我不知道如何取消设置自定义选项卡 当自定义选项卡为空时,如何从中隐藏WooCommerce产品简短描述?如果产品简短描述为空,以下内容将隐藏此自定义选项卡: // Add short description as a new custom product tab add_filter( 'woocommerce_product_tabs', 'add_custom_product_tab' );

我正在使用移动自定义产品选项卡中的Woocommerce产品简短描述

不幸的是,当没有简短的描述时,我不知道如何取消设置自定义选项卡


当自定义选项卡为空时,如何从中隐藏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.;
    }
}
//添加简短说明作为新的自定义产品选项卡
添加过滤器(“商业产品选项卡”、“添加自定义产品选项卡”);
功能添加自定义产品选项卡($tabs){
全球$post$product;
$short\u description=apply\u过滤器('woocommerce\u short\u description',$post->post\u摘录);
如果(!空($short_description)){
$tabs['short_description']=数组(
“title”=>“(盒子里有什么”,“woocommerce”),
“优先级”=>200,
“回调”=>“简短描述”选项卡“内容”
);
}
返回$tabs;
}
//自定义产品选项卡内容
功能简介\u说明\u选项卡\u内容(){
全球$post$product;
$short\u description=apply\u过滤器('woocommerce\u short\u description',$post->post\u摘录);
如果(!空($short_description)){
回显“.$short_description.”;//WPCS:XSS正常。;
}
}

代码进入活动子主题(或活动主题)的functions.php文件。已测试并正常工作。

如果产品简短说明为空,则以下内容将隐藏此自定义选项卡:

// 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.;
    }
}
//添加简短说明作为新的自定义产品选项卡
添加过滤器(“商业产品选项卡”、“添加自定义产品选项卡”);
功能添加自定义产品选项卡($tabs){
全球$post$product;
$short\u description=apply\u过滤器('woocommerce\u short\u description',$post->post\u摘录);
如果(!空($short_description)){
$tabs['short_description']=数组(
“title”=>“(盒子里有什么”,“woocommerce”),
“优先级”=>200,
“回调”=>“简短描述”选项卡“内容”
);
}
返回$tabs;
}
//自定义产品选项卡内容
功能简介\u说明\u选项卡\u内容(){
全球$post$product;
$short\u description=apply\u过滤器('woocommerce\u short\u description',$post->post\u摘录);
如果(!空($short_description)){
回显“.$short_description.”;//WPCS:XSS正常。;
}
}
代码进入活动子主题(或活动主题)的functions.php文件。测试和工作