Step by Step Guide on How to Remove WooCommerce Tabs in WordPress

WPTurbo » Snippets » Step by Step Guide on How to Remove WooCommerce Tabs in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you looking to simplify your WooCommerce product pages by removing unnecessary or unwanted tabs? By default, WooCommerce includes several tabs on product pages, including description, additional information, and reviews. However, not all these tabs may be useful to your specific needs. In this article, we’ll break down step-by-step, how to effectively remove WooCommerce tabs to streamline your ecommerce platform.

					add_filter( 'woocommerce_product_tabs', 'wpturbo_remove_woocommerce_tabs', 98 );
function wpturbo_remove_woocommerce_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;
}
				

The purpose of this code snippet is to remove specific tabs from the WooCommerce product page. This can be particularly useful if you want to simplify your product pages, or if you have necessary product information available elsewhere on your site.

The main action of this snippet is in the wpturbo_remove_woocommerce_tabs function, this function is designed to alter the tabs displayed on WooCommerce product pages.

The anatomy of the function is as follows:

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

The function accepts a single parameter, $tabs, which is an associative array that holds the configuration for all of the tabs currently set to be displayed on the WooCommerce product page. Each key in the array represents a particular tab.

Inside the function, we see three uses of unset(), a built-in PHP function that destroys specified variables. In this case, the variables being destroyed are different elements of the $tabs array. Specifically, the elements with keys ‘description’, ‘reviews’, and ‘additional_information’. The effect of unsetting these elements is to remove the respective tabs from the array, which will prevent them from being displayed on the product page.

In the order, the ‘description’ tab, the ‘reviews’ tab, and the ‘additional_information’ tab are set to be removed.

After the unset() calls, $tabs is returned. This is vital – by modifying $tabs and then returning it, we ensure that our changes persist beyond just this function.

The final part of the snippet handles attaching this behavior to the correct hook. The add_filter() function is used to bind wpturbo_remove_woocommerce_tabs() to the woocommerce_product_tabs filter hook. The "98" passed into add_filter() specifies the priority of this filter, determining the order in which filters are applied – a lower number means the filter is applied earlier.

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

In effect, this priority tells WordPress to run this function very late in the process, ensuring that all other modifications to the product tabs are made before the tabs are removed.

With this hook in place, the function will automatically run when WooCommerce is assembling the product tabs, removing the chosen tabs from every product page.

Register an account to save your snippets or go Pro to get more features.