WooCommerce: “Explode” Product Tabs

If you like the Amazon single product page layout, you probably dislike the default WooCommerce single product page tabs layout. This is the section where, by default, “Description”, “Reviews”, “Additional Information” and other custom content show… as tabs below the image & short description.

Thankfully, there is a super easy way to remove such tabs and display each tab on top of each other, without hiding any content. If it’s good for your users, then I recommend you make use of this super simple snippet.

In this tutorial, you will learn about “pluggable functions”. Basically, where provided, you can simply redeclare a custom plugin (WooCommerce) function without having to use hooks or overrides. WordPress will just “listen” to your new version and not the original one any longer.

So, enjoy!

Here’s the new layout after tabs “exploded”. As you can see, “Description”, “Reviews” and other tabs are stacked on top of each other and they are all visible. Cool, huh?

PHP Snippet: Stacking Product Tabs On Top Of Each Other @ WooCommerce Single Product Page

First of all, as I already said, tabs are displayed by WooCommerce thanks to this “pluggable” function:

if ( ! function_exists( 'woocommerce_output_product_data_tabs' ) ) {

	/**
	 * Output the product tabs.
	 */
	function woocommerce_output_product_data_tabs() {
		wc_get_template( 'single-product/tabs/tabs.php' );
	}
}

That’s great, so we can simply redeclare the woocommerce_output_product_data_tabs() PHP function and tell WordPress to listen to our new version:

/**
 * @snippet       Explode Tabs @ WooCommerce Single Product Page
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 5
 * @community     https://businessbloomer.com/club/
 */

function woocommerce_output_product_data_tabs() {
	$product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
	if ( empty( $product_tabs ) ) return;
	echo '<div class="woocommerce-tabs wc-tabs-wrapper">';
	foreach ( $product_tabs as $key => $product_tab ) {
		?>
			<h2><?php echo $product_tab['title']; ?></h2>		
			<div id="tab-<?php echo esc_attr( $key ); ?>">
				<?php
				if ( isset( $product_tab['callback'] ) ) {
					call_user_func( $product_tab['callback'], $key, $product_tab );
				}
				?>
			</div>
		<?php			
	}
	echo '</div>';
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

13 thoughts on “WooCommerce: “Explode” Product Tabs

  1. After i have ‘exploded’ the contents (long product description & reviews), there are 2 Description and 1 Review Header.

    How do i remove both headers?

    1. Hi Adrian!

      Simply remove this line:

      <h2><?php echo $product_tab['title']; ?></h2>
  2. This is a great feature. It does have 2 Descriptions and 2 Additional Information. How do delete one of each?

    Thannks.

    1. You mean 2 titles or the full tabs are duplicated?

  3. Thank you very much! :)))

    I discovered your site looking for this function and I’m enjoying everything here…

    First I tried to add this snippet via the Code Snippets plugin, but it did not allow me to publish, returning the message: “Cannot redeclare function woocommerce_output_product_data_tabs.”

    In functions.php it worked perfectly, however, the titles of the tabs are not shown anymore.

    The content was completely sequential, without being divided by the titles “Description”, “Additional Information”, “Review”, etc.

    Should this happen? How is it possible to show these titles again? Or, how can I show custom titles?

    Thank you again.

  4. Hi Rodolfo, when I try to activate this snippet I get the following error message:

    The code snippet has been disabled due to an error on line 2:

    Unable to redeclare the woocommerce_output_product_data_tabs function.

    1. Hello Tomas! Where did you place this code?

      1. Hi Rodolfo, with code snippets

        1. This won’t work with Code Snippets, you must place this code in your child theme’s functions.php

      2. Hi! Thank you so much for all of your snippets. They are awesome! I get an error when I use the snippets plugin. I guess I should add the code elsewhere. Can you tell me where? Thanks for everything you do!

        1. Hi Chris, functions.php of your child theme

          1. Code works but no titles for each section. anyway to get that back?

            1. Try with this revised version

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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