admin管理员组

文章数量:1129101

I want to remove the "additional information" tab, and append its content to the "description" tab. I had no problems adding new tabs or removing existing one. The problem is that, since I have to use a callback for the content of the tab, I do not know how to fetch the original content. My code:

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;
}

I don't know how to get the right content for the $description and $additional_information variables from the original content of the respective product tabs.

I want to remove the "additional information" tab, and append its content to the "description" tab. I had no problems adding new tabs or removing existing one. The problem is that, since I have to use a callback for the content of the tab, I do not know how to fetch the original content. My code:

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;
}

I don't know how to get the right content for the $description and $additional_information variables from the original content of the respective product tabs.

Share Improve this question asked Mar 1, 2019 at 17:24 DavidTonariniDavidTonarini 2113 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The callback used to render the "Description" tab is woocommerce_product_description_tab(), which simply loads the template file single-product/tabs/description.php. And for the "Additional Information" tab, the callback is woocommerce_product_additional_information_tab() and the template is single-product/tabs/additional-information.php.

So if you want to merge the two tabs, you can copy the "relevant" contents from the template file, like so:

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;
}

Alternate Version

Here we simply call the default callbacks and for the "Description" tab, we disable the default heading text.

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;
}

本文标签: woocommerce offtopicMerge quotdescriptionquot and quotadditional informationsquot product tab