How to remove the WooCommerce 2.0+ Reviews tab

March 7th, 2013 by Sean Barton Leave a reply »

woothemes-ninja3On the 6th of March (I think) the lovely guys at WooThemes graced us with a lovely new version of their fantastic WooCommerce plugin. They changed a lot of things, most of which I have yet to absorb. A couple of notable things though caught my eye. You may or may not be aware that I have written a few tutorials concerning the WooCommerce tab system. Adding new ones and, of course, removing the reviews tab. Since 2.0 the product tab API has been updated and is now somewhat slightly more elegant.

We now need to work around a single WordPress filter called ‘woocommerce_product_tabs’. You can add your own functions to this which receive a ‘tab’ array which you can manipulate and then return back. It’s quite important that when manipulating this you either don’t use the ‘priority’ setting of the filter system or, if you need to use it for some reason, make sure to use a priority less than 99. The reason for this is that you can now control where your tab shows in the list by adding another ‘priority’ setting.

For clarity the latter priority system lives in the ‘tabs’ array which controls the order of the tab. By default the Description tab is set to 10 and the Reviews tab is set to 20. Just slot yours in to suit. To avoid confusion in my code below I will explain both priority systems so that you don’t use one of them and use the other properly.

So.. removing the WooCommerce reviews tab is accomplished in 2.0 as follows:

add_filter( 'woocommerce_product_tabs', 'sb_woo_remove_reviews_tab', 98);
function sb_woo_remove_reviews_tab($tabs) {

 unset($tabs['reviews']);

 return $tabs;
}

You can rename the reviews tab (or any tab for that matter) using the following code making sure to substitute the ‘reviews’ bit for the index of the correct tab.

add_filter( 'woocommerce_product_tabs', 'sb_woo_rename_reviews_tab', 98);
function sb_woo_rename_reviews_tab($tabs) {

 $tabs['reviews']['title'] = 'Sausages';

 return $tabs;
}

So you can now also add new tabs to the new WooCommerce 2.0 system as follows:

add_filter( 'woocommerce_product_tabs', 'sb_woo_new_test_tab');
function sb_woo_new_test_tab_content() {
 echo '<h2>Hello World</h2>';

 echo '<p>You look hungry. Have some Sausages!</p>';
}

function sb_woo_new_test_tab($tabs) {
 $tabs['test_tab'] = array(
 'title' => __( 'Test Sausages', 'woocommerce' ),
 'priority' => 50,
 'callback' => 'sb_woo_new_test_tab_content'
 );

 return $tabs;
}

I would hope this is self explanatory but I will be more than happy to explain any of this code if it isn’t clear. I should point out something really important here. The priority system..

When removing the reviews tab (or any tab) you should use a priority of 98. This means that it will be processed just before the array is sorted and you will guarantee that the code runs after anyone else’s system adding their own reviews tab (or any other tab) as follows:

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

Note however that when adding a new tab we don’t need to/shouldn’t assign a priority as the WooCommerce 2.0 tab system actually orders the array by the tab priority (that which I set to 50 in the above example) anyway. So we use the following syntax omitting the priority setting:

add_filter( 'woocommerce_product_tabs', 'sb_woo_new_test_tab');

If you would like to know anything else about the WooCommerce 2.0+ API then please ask via the comments or submit one of the many contact forms on this site.

I should add that I have written many tutorials in and around the tab system in previous months and if you have yet to upgrade to 2.0 then you will need my original blog post on the subject.

Update:

Some people have asked how to rearrange tabs. This is accomplished as follows:

add_filter( 'woocommerce_product_tabs', 'sb_woo_move_reviews_tab', 98);
function sb_woo_move_reviews_tab($tabs) {
$tabs['reviews']['priority'] = 5;
return $tabs;
}

This will move the reviews tab to the start (unless anything has a priority lower than 5). It’s best to leave a gap instead of using 1 or 0 because you might want to put something before this later on and it saves you digging around for the code.

If you want to move your tabs around then simply use the following code to get a list of your tab names:

add_filter( 'woocommerce_product_tabs', 'sb_woo_debug_tabs', 98);
function sb_woo_debug_tabs($tabs) {

echo '<pre>';
print_r($tabs);
echo '</pre>';

return $tabs;
}

This will output an array of data to the screen. It should be fairly obvious which names you need to use. Once you have seen the output then remove the code and use the rearrange WooCommerce tabs example above  to do it.

Errors

Some people have been reporting the following error or similar for their WooCommerce sites:

Warning: uasort() [function.uasort]: The argument should be an array in …/wp-content/plugins/woocommerce/woocommerce-template.php on line 791

I want to reassure you that this is NOTHING to worry about except a bit of error catching needed to be added to the next version of WooCommerce if it’s not there already. Basically it happens then the tabs have been removed leaving nothing for the sorting function to parse. There is nothing we can do about this so it’s best to use the following code to sort it out.

Edit your theme functions.php file to add

<?php error_reporting(E_ERROR); ?>

This causes the system to only report errors when they are fatal (ie they will interrupt the page load) and not when small warnings and notices have been sound as with removing the last tab from the list. It should solve a lot of problems..

133 comments

  1. Sukrit says:

    Hi Sean,

    Great article. Quite useful. thanks for that.

    I was just wondering how I might be able to display selected product attributes in the new tab. I had implemented this on a previous version of Woocommerce, but I can’t seem to figure it out with the new version so far.

  2. Drew says:

    I did the following code I found from one of the devs in my functions.php file… Now I’m getting errors and no tabs are showing. Can you give me the code to put back ONLY description? Also, is it possible to just show the description but not the clickable button for description?

    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;

    }

    • Sean says:

      Hey Drew,

      That code is fine.. Just remove the line that says ‘remove the description tab’. That will then show the description tab accordingly. Also you can then use CSS to hide the tabs at the top.

      You could always make a theme modification and not show the tabs at all.. just call the description directly or something?

      ta
      S

  3. Matt says:

    Hi Sean,

    Everything worked great, I removed the reviews tabe and was able to add a new tab. I installed the “More Fields” plugin to add content to my new tab, gave it a text field and gave it a key name. My problem now is that I don’t know what to put into your code so it references whatever information is being entered into the new field. I’m not very familiar with wordpress at all and I’ve managed to stumble this far but I’m stuck.

    Thanks!

    • Sean says:

      Hey Matt,

      This is fine… The More Fields plugin asks you for a key name or field name when adding a new field. You need to add this name into the block of my code in the following format:

      echo get_post_meta(get_the_ID(), ‘your_key_name_here’, true);

      That goes in the content part of the tab. You can make it more complex if you like but this will pull that value from the database no problem.

      thanks
      Sean

  4. Hugh says:

    Hi Sean,

    Great tutorial!! How would I also remove the additional Info tab?? I have unchecked the attriibutes box (show on product page) but it still hasnt gone!

    • Sean says:

      Hi Hugh,

      The solution to that has been posted on this comments thread by others :)

      You basically just need to use the unset command but with the additional info name in there:

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

      thanks
      Sean

  5. Dana says:

    Hi, I would like to have the description above the attributes, so either:
    add the description to the second/attributes tab or
    add attributes to the first/description tab.

    I haven’t seen this asked before but if anyone knows the answer I figure it will be you!

  6. Johnny says:

    Hello Sean
    I am about to insert more that 400 product articles in my wootheme ATHENA (woocommerce) and I have to use 3 product (Additional 2 tabs) tabs for all products.
    I have used your advice in regards to adding a third field but how can I individually fill in that field for each product?
    For your info I also removed the review tab with your code.

    • Sean says:

      Hi Johnny, I don’t really know what you are asking. To get the new tab to appear you could follow my new tab tutorial or just follow the add new tab info in this page?

      thanks
      Sean

  7. sk says:

    Not sure if anyone posted about this already, but you can add an IF statement to avoid getting the error message that you mentioned people were experiencing when moving the tabs when the tab doesn’t exist.

    I did the below and it works nicely:

    add_filter( ‘woocommerce_product_tabs’, ‘re_woo_move_reviews_tab’, 98);
    function re_woo_move_reviews_tab($tabs) {
    if ($tabs['reviews']) {
    $tabs['reviews']['priority'] = 5;
    }
    return $tabs;
    }

    Hope it helps!

    • Sean says:

      Thanks SK..

      You can always just add an @ before the line which would be easier to read..

      @$tabs['reviews']['priority'] = 5;

      In theory it would suppress the error message. Reviews is a built in tab so unless you remove it it will always exist. Your code technically should be:

      if (isset($tabs['reviews'])) {

      But the thought is there I think. Thanks for the info.

      ta
      S

  8. Jericho says:

    I am most grateful, Sir!

  9. Ian Haney says:

    Hi

    I need to add a few tabs next to the description tab and was not sure what file I need to add the coding in that is above

    I need to add a review tab and a product attributes tab

    Is that possible if so, how do I do it?

    Sorry only been using wordpress for about 5 hours, not got the hang of it totally yet

    Kind regards

    Ian

    • Sean says:

      Hi Ian,

      Reviews is default when comments are enabled and attributes will be added automatically if they exist for that product. Any more help I can offer do let me know. I hope you like WordPress.. it’s an excellent choice for your site.. second to none!

      thanks
      S

  10. dlab says:

    Hi great post and really helped ive applied the tabs but need to link my custom fields to them. Im using http://www.advancedcustomfields.com plugin to create the fields but not sure how to display these in the tabs panel.
    Will that work with your code?

    • Sean says:

      Hi Dlab,

      You would need to use the custom field name from Advanced Custom Fields in the tab display code. It will work fine.

      thanks
      Sean

  11. Steve says:

    Is there any way to insert php *into* the product description tab? I want to add info to the bottom box, under the fed in data, but still be apart of the tab…

    • Sean says:

      Hi Steve,

      Yes you can do that. The description tab is the main content for that product and therefore you can use any plugin like Exec PHP to add PHP into there. You would just need to use a shortcode I expect.

      thanks
      Sean

  12. craig says:

    I added the code to the bottom of the themes-functions.php and it I still see the reviews on the product page.
    where should this code go?
    Thanks for any help.

    • Sean says:

      Hi there Craig,

      The code should go in your functions.php file.. this is as follows: /wp-content/themes/[theme_name]/functions.php

      I think you added it to the wrong file.

      thanks
      Sean

  13. Mieke Keeris says:


    Beschrijving

    Hello Sean,

    Thanks voor the tutorial. I added it to my private manual voor WordPress/woocommerce. Still a question left. Above Element I copied from my website. I would like to remove this ‘tab’, but can not find the code.

    Would you be so kind to help me?
    Thanks and best regards
    Mieke Keeris
    The Netherlands

    • Sean says:

      Hey there Mieke,

      You would need to use CSS to remove the tabs themselves. Removing the reviews tab will remove that tab but it will leave one left ‘product description’ which needs CSS to finish the job.

      Let me know how you get on.

      thanks
      Sean

      • Mieke Keeris says:

        Hi Sean, thanks for answering. This was my action in theme-functions.php:

        add_filter( ‘woocommerce_product_description_heading’, ‘remove_product_description_heading’ );
        function remove_product_description_heading() {
        return ”;

        That worked out, but there is still a irritating tab which I described before. Here a copy from the elements:


        Beschrijving

        which I would like to remove!

        If that is what you mean, that I have to leave it that way, it fine. Than I can stop searching.

        Thanks again
        Mieke

  14. Nevin says:

    Hi Sean,

    I need to remove the related products, I tried those line given above amending it to related products instead of reviews, but cant get it.

    Any advice?

    Nevin

    • Sean says:

      Hey Nevin.

      No problem at all. You can add the following to your functions.php file to remove the WooCommerce related products section…

      remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 );

      Let me know if this works ok.

      thanks
      Sean

  15. jackie says:

    Hi Sean, I want to rename the review tab but after reading your post I still dont know how to do it. Where should I insert the code you mentioned in the post? I am new to wordpress and website design… Thanks a lot!

    • Sean says:

      No problem at all Jackie, you would add this code into your theme functions.php file /wp-content/themes/[your_theme_name]/functions.php

      Let me know if you need further assistance with this.

      thanks
      Sean

  16. jackie says:

    I made it!!!! thanks a lot Sean!

  17. jackie says:

    Hey Sean, after I add the code to change the name of the tab “comments” I got an error message in some of my product pages:

    Warning: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in /homepages/19/d458370762/htdocs/app458370778/wp-content/plugins/woocommerce/templates/single-product/tabs/tabs.php on line 35

    what should I do to fix this? Thanks a lot!

  18. mrBurns says:

    Well writte, quite understandable!

    I just don’t get one thing:
    If I add the code to the functions.php, it doesn’t just hide the tabs at the bottom of the page, but also the product description at the top.
    Is there a way to avoid that?

    Thanks,
    Felix

    • Sean says:

      Hi Felix,

      I suspect your theme is doing something a little odd as there should only be a single set of tabs on the page. Perhaps investigate the top description tab. Try adding the_content(); in it’s place which should sort it.

      ta
      S

  19. shaloam says:

    Please help. I have managed to add the new tab by pasting the code into functions.php however I can’t find the panel to enter the content for the tab. How do I add this?

  20. sola says:

    Hi Sean, i’ve put in those codes in my function.php and its not working. Theme i’m using is near impossible to customize, please can you help me. Thankyou

    • Sean says:

      Perhaps you are using an old version of Woo? Also you can try and delay the filter by adding the code to:

      add_action(‘init’, ‘my_delayed_function’, 99,);

      function my_delayed_function() {
      //line here
      }

  21. Georgi says:

    Hey Sean,
    I would like to have the tag-description added in front of the “short description” of a product. I have a very basic knowledge of php but I managed to put this in the tabs/description.php file with success:

    ID , ‘product_tag’ );
    if($terms) {
    foreach( $terms as $term ) {
    echo $term->description.”;
    }
    }
    ?>

    Unfortunately when the short description content is empty it doesn’t work. Can you help me?

    • Sean says:

      Hey Georgi,

      You would be better to add a new tab using my tabs plugin and then adding this code with the short description code below. I suspect the existing description tab doesn’t show if the short description is empty and is unaware of your changes. If you write a new tab then this won’t be the issue and it should work.

      ta
      S

  22. Kat says:

    Thanks for this post, really helpful!

    I tried this to remove the ‘description’ tab and it worked a treat, however I need the text part to remain and the unstyled actual ‘tab’ to be gone.

    Do you know how I could achieve this?

    Many thanks

  23. Kat says:

    oh btw, you can actually disable the reviews tab in the backend by unchecking ‘enable reviews’ under the advanced settings tab below the description edit.

    • Sean says:

      You can indeed but that only works on a per post basis whereas this fix is for all products.

      Still.. your comment is both valid and useful if you want to do it that way.

  24. Tejas says:

    Hey Sean,

    Great tutorial. I’ve found the things I hope to accomplish. I’m absolutely new to woocommerce. So could you also help me out with where am I suppose to put the code you’ve given above.

    This may sound like a very stupid question to a programmer of your level of expertise, but your help will be highly appreciated.

    Thanks in advance.

    • Sean says:

      No problem at all. You put it in your theme functions.php file.. /wp-content/themes/[theme name]/functions.php .. put it at the end of the file before the ?> line and it should work.

      thanks
      Sean

  25. Celine says:

    Hello, i added this to my file, but i still see the tab: beschrijving. Can you please help me?

    add_filter( ‘woocommerce_product_tabs’, ‘sb_woo_rename_reviews_tab’, 98);
    function sb_woo_rename_reviews_tab($tabs) {

    $tabs['reviews']['title'] = ‘Sausages’;

    return $tabs;
    }

    • Sean says:

      Sometimes themes override this. You can wrap the above statement in a filter or action to delay the execution as follows:

      add_action(‘init’, ‘sb_init’);

      function sb_init() {
      add_filter( ‘woocommerce_product_tabs’, ‘sb_woo_rename_reviews_tab’, 98);
      }

      This should work but if init you can change ‘init’ to something like ‘the_post’ or another action later in the page load.

      S

Trackbacks /
Pingbacks

Leave a Reply