Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove single product tabs and add the related content instead In Woocommerce

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?

like image 277
jimiayler Avatar asked Dec 23 '22 09:12

jimiayler


1 Answers

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

like image 69
LoicTheAztec Avatar answered Dec 29 '22 00:12

LoicTheAztec