General Solutions&FAQ

Print

How to edit Woocommerce product tabs

woocommerce-product-tabs

So many projects, so many changes should be done and today, we’ll talk about Woocommerce product tabs and how to edit all of them. Even how to add a new one, if needed.

In some cases, for users without any experience, we recommend using Code Snippets plugin to ease the way of code adding to your live site. But not now, just copy/paste needed code below straight to child theme’s functions.php:

  1. Use the following code to remove specific tabs
/**
* Remove product data tabs
*/
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;
}

2. Use the following code to rename tabs

/**
* Rename product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
$tabs['description']['title'] = __( 'More Information' ); // Rename the description tab
$tabs['reviews']['title'] = __( 'Ratings' ); // Rename the reviews tab
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab
return $tabs;

}

3. Use the following code to change the tab order

/**
* Reorder product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
$tabs['reviews']['priority'] = 5; // Reviews first
$tabs['description']['priority'] = 10; // Description second
$tabs['additional_information']['priority'] = 15; // Additional information third
return $tabs;
}

4. The following code will replace the description tab with a custom function

/**
* Customize product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback

return $tabs;
}

function woo_custom_description_tab_content() {
echo '<h2>Custom Description</h2>';
echo '<p>Here\'s a custom description</p>';
}

5. Use the following code to add a custom global product tab

/**
* Add a custom product data tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}

Leave a Reply

Your email address will not be published. Required fields are marked *