4

I have a client who wants to pull the information that defaults into tabs on single product pages in WooCommerce into a different location on the page and remove the tabs entirely.

There are three default product tabs:

  • product Description,
  • Additional Information
  • and Reviews.

Removing the tabs and setting up the Description to display was easy enough to set up in
/wp-content/plugins/woocommerce/includes/wc-template-hooks.php:

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

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

That works fine.

I tried to repeat the process by building out new functions that access the template files for Additional Info and Reviews like so:

function woocommerce_template_product_addinfo() {
  woocommerce_get_template( 'single-product/tabs/additional-information.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_addinfo', 20 );

function woocommerce_template_product_reviews() {
  woocommerce_get_template( 'single-product/review-rating.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_reviews', 30 );

But neither is displaying. What am I doing wrong here?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
jimiayler
  • 674
  • 2
  • 11
  • 27

1 Answers1

10

First woocommerce_get_template() is deprecated and replaced by wc_get_template() instead. After some searching and testing (mainly to get the reviews displayed), I have found the way:

add_action( 'woocommerce_after_single_product_summary', 'removing_product_tabs', 2 );
function removing_product_tabs(){
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
    add_action( 'woocommerce_after_single_product_summary', 'get_product_tab_templates_displayed', 10 );
}
function get_product_tab_templates_displayed() {
    wc_get_template( 'single-product/tabs/description.php' );
    wc_get_template( 'single-product/tabs/additional-information.php' );
    comments_template();
}

Code goes in function.php file of your active child theme (or theme). Tested and work (WC 3+).

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • That does it -- my thanks to you for this and for cleaning up my question. – jimiayler Mar 09 '18 at 18:39
  • 1
    @jimiayler You are welcome … It was not so easy to find out… but now it works :) – LoicTheAztec Mar 09 '18 at 18:42
  • Agreed on the difficulty of trying to achieve this kind of basic re-configuring of WooCommerce's UI -- other platforms are much more transparent in this regard. – jimiayler Mar 09 '18 at 18:49
  • 1
    It works! As wc_get_template( 'single-product-reviews.php' ); didn't when unsetting the reviews tab! – Alchem Aug 10 '20 at 15:41