How to remove the WooCommerce 2.0+ Reviews tab

March 7, 2013 | Ecommerce, PHP, Plugins, Time Savers, Tutorials, WooCommerce, Wordpress | 131 comments

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..

A Donate Button!

131 Comments

  1. Kat

    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.

    Reply
    • Sean

      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.

      Reply
  2. Tejas

    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.

    Reply
    • Sean

      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

      Reply
  3. Celine

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

    Reply
    • Sean

      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

      Reply
  4. Martin Spence

    Hi Sean

    Thanks for sharing this, I added the code:

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

    unset($tabs[‘reviews’]);

    return $tabs;
    }

    to my functions.php file.

    However the Review tab did not disappear – what else do I need to do?

    Page is:
    http://www.martinspencephotography.co.uk/shop/east-strand/

    Reply
  5. Håkon Stillingen

    Hi Sean.

    Thanks for providing this. Do you know of a way of displaying product reviews without the use of tabs? The reason for asking is that I got feedback from Google Rich Snippets team that Google consider tabs as “hidden” content, and therefore not displaying schema.org data on my site.

    Reply
    • Sean

      Hey there.. yes the review system is based on comments so you should be able to simply use comments_template(); in the woocommerce theme and it should, in theory, work.

      Reply
  6. Gaelle

    I just wanted to thank you for this blog Sean. Was helpful for me, even if I’m french and not so good at coding !

    Reply
  7. Sunil

    The solutions in the post remove the reviews tab, but leave the ‘description’ tab. So the UI now makes no sense.

    Developers should seriously avoid woocommerce: the templating system is a complete mess. All the customization is done by complicated hooks, and the actual markup is hidden.

    This is the perfect arse-backward way to do things.

    Friends don’t let friends use woocommerce.

    Reply
    • Sean

      I completely disagree with you on the shy away from Woo. WooCommerce is the best eCommerce offering that WP has and frankly it’s not too hard to remove the tabs all together but it’s a half decent way of showing lots of data in a compact manner. Normally adding another tab for superflous data is an easy workaround for amateurs. The templating system is based on overrides which is raved about by some big names in the WP industry. You don’t need to use the hooks although to be honest that is the accepted way to work with WP plugins in order to make them hugely customisable. Using the hook system in conjunction with the template fallback system you can create very good abstracted themes which work perfectly with WooCommerce. All in a few lines of code. Plus the hook system stops people from messing with the core markup whereas with WP-eCommerce you are given the processing code as part of the templating system which is far easier to, and frequently is, break.

      Still.. all comments gratefully received. Each entitled to their own opinion and all. Woo have gone downhill recently as their themes are harder to work with than competitors like ElegantThemes and they are in the premium market definitely so things are becoming more awkward that’s for sure. Still I have a lot of faith in WooThemes as a brand which is more than I can say for a lot of the theme houses lurking around the Envato network.

      Reply
  8. Gian

    Hi Sean,

    Thanks for the tutorial, really brilliant. The code is working great but I just have a tiiiiiiiny issue or doubt. My additional tab is showing up perfectly in the website front end….but how can I add it to my product edit/add screen in wp-admin? I need to add info which is relevant to each different product….

    Thanks!

    Reply
    • Sean

      Yup this would work ok. You would just need to use my WooCommerce 2.0 tutorials on making a new tab or just replacing the existing reviews tab in the code.

      ta
      S

      Reply
  9. Simon

    Thanks for sharing this Sean, really helpful.

    Reply
  10. James

    Thanks for the great tutorial!

    Quick question – how would I add multiple new tabs?

    Repeating the code above twice only displays the tab that has been coded lower down in the function.php. Is this because they’re both going through the same filter?

    Reply
  11. Justin D

    Hi, great tutorials. I have what is probably a difficult question to answer. How do I go about adding in another field box to the review template page. As In I want to create a kind of survey form rather than just 1 text field.

    Im having trouble getting my head around WooCommerce single-product-review.php file and adding in new meta data. If you could run through a tutorial on how to add new metadata to the review page that would be very much appreciated.

    Anyway, keep up the good work.

    Reply
  12. Roman

    Helped me a lot !
    great article, well explained !
    Thanks

    Reply
  13. Elf

    Worked great for me. WordPress 3.9.1, WooCommerce 2.1.9. Thank you Sean!

    Reply
  14. Mendert

    Great article! Is it also possible to split the tabs in a two column?

    I would like to make a 1/4,1/2,1/4 page. With the description in the 1/2 and the add to cart button and price in the last 1/4.

    Reply
  15. Ali

    Hi, Thank you for the solution I’ve checked your other post regarding this but this one worked for me not the other one and I think that is because of :

    return $tabs;

    Reply
  16. karthikphp

    Hello
    I want to show reviews tab in separate area like above footer. Can anyone tell me to show

    Reply

Trackbacks/Pingbacks

  1. WooCommerce einrichten Teil 1 – Grundeinstellungen & Produkte » MarketPress Deutschland - […] komplett auf Kundenrezensionen sowie den zugehörigen Reiter „Bewertungen“ verzichten, so hilft diese Anleitung weiter.   Über die Produktbildgrößen legt…
  2. Setting up WooCommerce Part 1 – Basic Settings & Products » MarketPress - […] If you want loose customer reviews and the “Reviews” tab altogether, this instruction may help.   At Product Image…

Leave a Reply to Martin Spence Cancel reply

Divi United

About this site and Sean Barton

Picture of Sean
Sean Barton is a Freelance PHP Website Developer in Crewe, Cheshire. He is a Wordpress and CMS/Framework specialist.
This site was set up in 2008 as a tutorial and scripting resource for the PHP language and Wordpress.
Find out more about Sean on the About Me page or use the Hire Me page to get in touch. For more information about Sean's work take a look at the Portfolio

Our Services

  • Wordpress plugin/theme development
  • Divi specialist
  • Ecommerce (Woocommerce, WPSC, Shopify, Magento)
  • PSD to Wordpress theme conversion (Responsive)
  • Website design work (Banners, Logos, Full Site, etc)
  • Website analysis (security, usability, SEO)
  • API Integrations (InfusionSoft, SalesForce, Ontraport, Customer Thermometer, etc..)
  • Wordpress consultancy & expert advice
  • Crisis support
  • Website hosting

The main services offered are Wordpress based although we do a great deal of technical programming for bespoke systems. From troubleshooting, extending frameworks, finding bugs to writing them from scratch.

Find out more by looking through our past projects or get a quote.

Be the first to hear about new products/updates!

This is a mailing list for those people interested in being told when we release a new product (Divi plugin or Theme).

We shall also use this list to let you know about product updates and releases.

You have Successfully Subscribed!