中删除单个产品选项卡并添加相关内容

中删除单个产品选项卡并添加相关内容

本文介绍了在 Woocommerce 中删除单个产品选项卡并添加相关内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户想要将 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:

  • 产品描述,
  • 其他信息
  • 和评论.

删除选项卡并设置要显示的描述非常容易,可以在
中进行设置/wp-content/plugins/woocommerce/includes/wc-template-hooks.php:

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

效果很好.

我尝试通过构建访问附加信息评论的模板文件的新函数来重复该过程,如下所示:

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?

推荐答案

第一个 woocommerce_get_template() 已弃用,取而代之的是 wc_get_template().经过一些搜索和测试(主要是为了显示评论),我找到了方法:

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

代码位于您的活动子主题(或主题)的 function.php 文件中. 测试并运行 (WC 3+).

这篇关于在 Woocommerce 中删除单个产品选项卡并添加相关内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:27