How to remove woocommerce tab?
Asked Answered
B

7

14

the products in our woocommerce shop don't need any of the default tabs so I have managed to disable them being that I only need to have the product description below the product however, while I want to keep the actual description, I believe the tab itself is redundant since there aren't any other tabs.

Basically, I want to remove the tab's & title altogether but keep the content box below it without modifying the woocommerce core php template file. Is there a way to add a filter to my WordPress theme's functions.php?

function woocommerce_default_product_tabs( $tabs = array() ) {
    global $product, $post;

    // Description tab - shows product content
    if ( $post->post_content ) {
        $tabs['description'] = array(
            'title'    => __( 'Description', 'woocommerce' ),
            'priority' => 10,
            'callback' => 'woocommerce_product_description_tab'
        );
    }
Bertrando answered 12/6, 2015 at 20:48 Comment(0)
S
31

While CSS is great, if the stylesheet doesn't load correctly, you could end up showing someone tabs without meaning to. It is best to remove the content before loading (server side), by using a filter, as you had mentioned.

See code below as provided from Woothemes for unsetting data tabs.
EDIT Place within the functions.php file inside your theme.

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

EDIT As noted by @BasvanDijk To remove altogether, you can use the following

add_filter( 'woocommerce_product_tabs', '__return_empty_array', 98 );
Sonny answered 29/4, 2016 at 12:18 Comment(7)
Just out of curiosity why did you give it a priority of 98?Surfing
Other than making sure it ran last, might've turned out to be a typo for 99? Trying to channel 3 years younger me.Sonny
@Surfing Normally I use PHP_INT_MAX for my priority to ensure it runs after all other plugins adding tabs. This way you have the final say on what stays on the product page!Fiche
You could better just return an empty array. function() { return []; } or using a callback like __return_empty_array()Swaim
@BasvanDijk - but what if you want to only remove some tabs?Sonny
@Sonny OP said he wanted to remove the tab's altogether.Swaim
@BasvanDijk - fair enough, but then I suppose it becomes a 1 dimensional answer. I'll add in your suggestionSonny
P
5

If you want to remove tabs from woo-commerce product details page, then add this code in your function.php

Option 1-

Go to functions.php and Add the following code. (Go to Admin panel > Appearance > Editor > functions.php)

add_filter( 'woocommerce_product_tabs', 'woo_remove_tabs', 98 );
function woo_remove_tabs( $tabs ){
    if(is_product()){
      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;
 }

By using this filter we can Remove the tabs From the Woocommerce Product Pages.

Option 2-

Or for an alternative approach just add this to your functions.php

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10);

Option 3-

Hide the tab by adding this to the bottom of woocommerce.css

 .woocommerce_tabs .tabs {
    display: none;
}

Read more -Woo-commerce: Remove tab from product page

Parmer answered 21/7, 2016 at 6:8 Comment(0)
I
2
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;
}

function woocommerce_template_product_description() {
    woocommerce_get_template( 'single-product/tabs/description.php' );
}

add_action( 'woocommerce_after_single_product_summary',  'woocommerce_template_product_description', 40 );

This work for me with the contributions i got here. Other than removing the tab and also to place back the text.

Credits to Swapnali & Mustafa

Imaimage answered 2/9, 2020 at 8:56 Comment(0)
D
0

Here is the working code:

add_filter( 'woocommerce_product_tabs', 'wcs_woo_remove_reviews_tab', 98 );
function wcs_woo_remove_reviews_tab($tabs) {
unset($tabs['reviews']);
return $tabs;
}
Doloritas answered 8/11, 2016 at 10:40 Comment(0)
N
0

Excuse me but the question is not only removing tabs but also keeping the product description. If you ever tried the code above you would realize that while removing tabs you are actually removing the product description. And this is not the desired case.

You should somewhere add the following code to add it back. But unfortunately this time you can add the description side by side the picture and making a narrow column. I couldn't find the solution to add it nicely below the picture where the tabs existed before. The code:

function woocommerce_template_product_description() {
    woocommerce_get_template( 'single-product/tabs/description.php' );
}

add_action( 'woocommerce_single_product_summary',  'woocommerce_template_product_description', 40 );
None answered 9/12, 2016 at 16:15 Comment(1)
Couldn't you just use a variation of what I provided, in the sense that you don't unset description? ie - comment out unset( $tabs['description'] );Sonny
K
0

for some reason the code to add to functions.php file did not work for me, even tho it is in the woo commerce codex.

I was getting lots of comment spam to these products that showed reviews.

in the end I manually removed the review tab from all the products using built in wordpress/woocommerce functionality.

  1. go to the product lising page
  2. click the checkbox to select all products (it will only select the products on this page so you may have to go thru several pages to repeat)
  3. from the bulk actions drop down, select edit
  4. click apply
  5. you will now see all the bulk edit actions you can do. Choose the "comments" drop down, and select "Do not allow"
  6. click update
  7. make sure to delete any cache if using a caching plugin

removing comments or reviews from woo commerce products

Keyes answered 23/2, 2017 at 14:15 Comment(0)
L
0

Using a combination of the answers above, nesting the function within the action so you can use within a conditional:

add_action( 'wp', 'custom_remove_tabs_by_tag' );
function custom_remove_tabs_by_tag() {
if ( is_product() && has_term( 'tag-term', 'product_tag' ) ) 
{    
    // Remove All Product Tabs
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
    // Add Product Description
    add_action( 'woocommerce_after_single_product_summary',
                 function () { woocommerce_get_template( 'single-product/tabs/description.php' );}, 
                 40 );
}
Liverpudlian answered 20/2, 2021 at 21:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.