Woocommerce: delete “additional information” tab

2019-08-11 08:28发布

问题:

Two things I am trying to do on the product pages of this website: https://lovesometea.com/product/green-coconut/

1) Delete "additional information" tab 2) Add Attribute "Size" above the product description

To delete the "additional information" tab, I have been following this: https://idevie.com/tutorials/how-to-make-woocommerce-product-attributes-more-prominent

So this is what I did: 1) Added a custom plug-in and activated it - http://code.tutsplus.com/tutorials/making-woocommerce-product-attributes-more-prominent--cms-25438

2) Tried removing "additional information" by editing the tabs.php in /wp-content/plugins/woocommerce/templates/single-product/tabs

/**
 * Removes the "Additional Information" tab that displays the product attributes.
 * 
 * @param array $tabs WooCommerce tabs to display.
 * 
 * @return array WooCommerce tabs to display, minus "Additional Information".
 */
function tutsplus_remove_product_attributes_tab( $tabs ) {

    unset( $tabs['additional_information'] );

    return $tabs;

}

add_filter( 'woocommerce_product_tabs', 'tutsplus_remove_product_attributes_tab', 100 );

This is where I'm stuck. I even tried deleting the additional-information.php file all together (in the same tabs folder) and additional information still displays!

I tried putting the above code in three different areas of the tabs.php file but no effect on the tab on the product page.

Any other suggestions? Perhaps there is a different/better method with the latest woocommerce version?

回答1:

This worked for me for removing the tabs:

Adding this in functions.php:

add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );

function woo_remove_product_tabs( $tabs ) {

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

    return $tabs;

}

To return the attributes to display under description, I couldn't figure it out so I just added the sizes in the description



回答2:

Maybe you need to change the priority from 100 to 98 as in woocommerce documentation , put the code in functions.php file

add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );

function woo_remove_product_tabs( $tabs ) {

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

    return $tabs;

}