合并“Description”和“Additional Information”产品标签

时间:2019-03-01 作者:DavidTonarini

我想删除“附加信息”选项卡,并将其内容附加到“描述”选项卡。添加新选项卡或删除现有选项卡都没有问题。问题是,由于我必须对选项卡的内容使用回调,我不知道如何获取原始内容。我的代码:

add_filter( \'woocommerce_product_tabs\', \'exetera_custom_product_tabs\', 98 );
function exetera_custom_product_tabs( $tabs ) {


 $tabs[\'description\'][\'callback\'] = function ( ) {
        $description = "Original content of the description tab here";
        $additional_information = "Original content of the Additional Information tab here";
        echo $description;
        echo $additional_information;
        };  // Custom description callback
 unset( $tabs[\'additional_information\'] );      // Remove the additional information tab

return $tabs;
}
我不知道如何从各个产品选项卡的原始内容中获取$description和$additional\\u信息变量的正确内容。

1 个回复
最合适的回答,由SO网友:Sally CJ 整理而成

用于呈现“描述”选项卡的回调是woocommerce_product_description_tab(), 只需加载模板文件single-product/tabs/description.php. 对于“附加信息”选项卡,回调是woocommerce_product_additional_information_tab() 模板是single-product/tabs/additional-information.php.

因此,如果要合并这两个选项卡,可以从模板文件中复制“相关”内容,如下所示:

add_filter( \'woocommerce_product_tabs\', \'exetera_custom_product_tabs\', 98 );
function exetera_custom_product_tabs( $tabs ) {
    // Custom description callback.
    $tabs[\'description\'][\'callback\'] = function() {
        global $post, $product;


        // Display the content of the Description tab.
        the_content();


        // Display the heading and content of the Additional Information tab.

        echo \'<h2>Additional Information</h2>\';

        do_action( \'woocommerce_product_additional_information\', $product );
    };

    // Remove the additional information tab.
    unset( $tabs[\'additional_information\'] );

    return $tabs;
}
在这里,我们只调用默认回调,对于“描述”选项卡,我们禁用默认标题文本。

add_filter( \'woocommerce_product_tabs\', \'exetera_custom_product_tabs\', 98 );
function exetera_custom_product_tabs( $tabs ) {
    // Custom description callback.
    $tabs[\'description\'][\'callback\'] = function() {
        // Disable the "Description" heading.
        add_filter( \'woocommerce_product_description_heading\', \'__return_empty_string\' );

        // Display the content of the Description tab.
        woocommerce_product_description_tab();

        // Enable the "Description" heading.
        remove_filter( \'woocommerce_product_description_heading\', \'__return_empty_string\' );


        // Display the heading and content of the Additional Information tab.
        woocommerce_product_additional_information_tab();
    };

    // Remove the additional information tab.
    unset( $tabs[\'additional_information\'] );

    return $tabs;
}

相关推荐