merge tabs in woocommerce

admin2025-06-02  2

i merged the description and the additional information tab. the additional information content is shown in the description tabs.

it works fine, but the content from additional information is shown above the description content. i cant figure out why...

add_filter( 'the_content', 'customizing_woocommerce_description' );
function customizing_woocommerce_description( $content ) {

    // get attributes
    global $product;
    $attributes = do_action( 'woocommerce_product_additional_information', $product );


    // Only for single product pages (woocommerce)
    if ( is_product() ) {

        // The custom content
        $custom_content = $attributes;

        // Inserting the custom content at the end
        $content .= $custom_content;
    }
    return $content;
}



// Manipulating product tabs
add_filter('woocommerce_product_tabs', 'change_product_tab', 98);
function change_product_tab($tabs){
    global $product;

    // Remove tabs
    unset($tabs['additional_information']);

    return $tabs;
}

i merged the description and the additional information tab. the additional information content is shown in the description tabs.

it works fine, but the content from additional information is shown above the description content. i cant figure out why...

add_filter( 'the_content', 'customizing_woocommerce_description' );
function customizing_woocommerce_description( $content ) {

    // get attributes
    global $product;
    $attributes = do_action( 'woocommerce_product_additional_information', $product );


    // Only for single product pages (woocommerce)
    if ( is_product() ) {

        // The custom content
        $custom_content = $attributes;

        // Inserting the custom content at the end
        $content .= $custom_content;
    }
    return $content;
}



// Manipulating product tabs
add_filter('woocommerce_product_tabs', 'change_product_tab', 98);
function change_product_tab($tabs){
    global $product;

    // Remove tabs
    unset($tabs['additional_information']);

    return $tabs;
}
Share Improve this question asked Mar 13, 2019 at 16:59 LovinQuaQuaLovinQuaQua 833 silver badges19 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

the content from additional information is shown above the description content

Because the following code calls wc_display_product_attributes() which displays the default content for the additional information tab:

do_action( 'woocommerce_product_additional_information', $product );

To fix it, you can turn on output buffering, run the do_action() and then get the output using ob_get_clean():

function customizing_woocommerce_description( $content ) {

    // get attributes
    global $product;

    // Only for single product pages (woocommerce)
    if ( is_product() ) {

        // The custom content
        ob_start();
        do_action( 'woocommerce_product_additional_information', $product );
        $custom_content = ob_get_clean();

        // Inserting the custom content at the end
        $content .= $custom_content;
    }

    return $content;
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748810012a313908.html

最新回复(0)