首页 > 解决方案 > woocommerce 删除所有标签,在页面上显示其内容

问题描述

在尝试了我能找到的每个功能并尝试了 2 天以上的功能后,我一直无法找到一个可行的解决方案。

我正在尝试删除 WooCommerce 描述和评论选项卡,并仅显示描述代替选项卡,并在其下方显示评论选项卡的内容......没有可单击的选项卡。- 我取消设置选项卡并删除,但无法重新添加它们的内容。

我已尝试删除单个产品选项卡并在 Woocommerce 中添加相关内容答案代码。

我什至不介意在主题中覆盖 php,但似乎没有任何效果......目标只是让描述显示,并且下面的评论没有标签。任何帮助表示赞赏。

标签: phpwordpresswoocommercetabsproduct

解决方案


要删除选项卡但显示内容,您可以使用以下内容。

// Remove
function remove_product_tabs( $tabs ) {
    unset( $tabs['description'] );
    unset( $tabs['reviews'] );
    unset( $tabs['additional_information'] );
    return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'remove_product_tabs', 98, 1 );

// Tabs callback function after single content.
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_product_description_tab' );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_product_additional_information_tab' );
add_action( 'woocommerce_after_single_product_summary', 'comments_template' );

为避免折叠,请编辑以下模板

https://github.com/woocommerce/woocommerce/blob/master/templates/single-product/tabs/description.php

  • 此模板可以通过将其复制到yourtheme/woocommerce/single-product/tabs/description.php.

代替

<?php if ( $heading ) : ?>
    <h2><?php echo esc_html( $heading ); ?></h2>
<?php endif; ?>

<?php the_content(); ?>

<div style="clear:both;">
<?php if ( $heading ) : ?>
    <h2><?php echo esc_html( $heading ); ?></h2>
<?php endif; ?>

<?php the_content(); ?>
</div>

进一步的定制是 html 和/或 css 修改的问题,具体取决于您的主题


推荐阅读