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

和自甴很熟 提交于 2019-12-21 19:43:27

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/49196441/remove-single-product-tabs-and-add-the-related-content-instead-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!