【问题标题】:woocommerce reviews are not showing but the review form is working perfectly okaywoocommerce 评论未显示,但评论表单运行良好
【发布时间】:2022-01-18 00:35:04
【问题描述】:

我在电子商务网站工作,我制作了自己的主题并安装了 woocommerce 插件。但显示产品评论时出现问题。

下面的代码在 woocommerce/single-product/tabs/tabs.php 中

<?php
/**
 * Single Product tabs
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product/tabs/tabs.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce\Templates
 * @version 3.8.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Filter tabs and allow third parties to add their own.
 *
 * Each tab is an array containing title, callback and priority.
 *
 * @see woocommerce_default_product_tabs()
 */
$product_tabs = apply_filters( 'woocommerce_product_tabs', array() );

if ( ! empty( $product_tabs ) ) : ?>
    <div class="woocommerce-tabs wc-tabs-wrapper" >
        <ul class="tabs wc-tabs" role="tablist">
            <?php foreach ( $product_tabs as $key => $product_tab ) : ?>
                <li class="<?php echo esc_attr( $key ); ?>_tab" id="tab-title-<?php echo esc_attr( $key ); ?>" role="tab" aria-controls="tab-<?php echo esc_attr( $key ); ?>">
                    <a href="#tab-<?php echo esc_attr( $key ); ?>">
                        <?php echo wp_kses_post( apply_filters( 'woocommerce_product_' . $key . '_tab_title', $product_tab['title'], $key ) ); ?>
                    </a>
                </li>
            <?php endforeach; ?>
            <li class="reviews_tab" id="tab-title---><?php //echo esc_attr( $key ); ?><!--" role="tab" aria-controls="tab---><?php //echo esc_attr( $key ); ?><!--">
                <a href="#tab-reviews">
                    Reviews
                </a>
            </li>
        </ul>
        <?php foreach ( $product_tabs as $key => $product_tab ) : ?>
            <div class="woocommerce-Tabs-panel woocommerce-Tabs-panel--<?php echo esc_attr( $key ); ?> panel entry-content wc-tab" id="tab-<?php echo esc_attr( $key ); ?>" role="tabpanel" aria-labelledby="tab-title-<?php echo esc_attr( $key ); ?>">
                <?php
                if ( isset( $product_tab['callback'] ) ) {
                    call_user_func( $product_tab['callback'], $key, $product_tab );
                }
                ?>
            </div>
        <?php endforeach; ?>
        <div class="woocommerce-Tabs-panel woocommerce-Tabs-panel--reviews panel entry-content wc-tab" id="tab-reviews" role="tabpanel" aria-labelledby="tab-title-reviews">
            <div id="reviews">
                <?php
                woocommerce_get_template_part( 'single-product-reviews' );
                ?>
            </div>
        </div>
        <?php do_action( 'woocommerce_product_after_tabs' ); ?>
    </div>
<?php endif; ?>

过去 2 天我一直在解决这个问题,但不明白为什么它没有显示评论

【问题讨论】:

    标签: php wordpress woocommerce review


    【解决方案1】:

    为了显示产品评论,您需要确保几件事

    1. 在 WooCommerce --> 常规下产品选项卡上的设置中,确保您已勾选“启用产品评论”
    2. 在“高级”下的实际产品中勾选“启用评论”
    3. 此外,在设置自定义主题时,如果您要覆盖单个产品的默认模板,则需要确保包含 woocommerce_after_single_product_summary 操作,因为它包含 woocommerce_output_product_data_tabs,其中包括显示产品评论
        /**
         * Hook: woocommerce_after_single_product_summary.
         *
         * @hooked woocommerce_output_product_data_tabs - 10
         * @hooked woocommerce_upsell_display - 15
         * @hooked woocommerce_output_related_products - 20
         */
        do_action( 'woocommerce_after_single_product_summary' );
    

    这是一篇文章的链接,其中包含进一步解释第 1 步和第 2 步的图片 Reviews not showing on product page

    【讨论】:

    • 这也不起作用。我已经尝试过了,但它没有显示它。但是如果我写 cmets_template() 它会显示 cmets 被复制而不是我想要的位置
    • 我可以看到您已经自定义了 woocommerce/single-product/tabs/tabs.php,当我尝试它时,它会导致评论选项卡出现两次,一次是“评论 (x)”,然后是“评论”。如果您从主题中删除自定义文件并使用默认的 woocommerce 文件会发生什么情况,如果您按照上面的步骤 1 设置它,默认情况下会显示评论选项卡。然后你会看到评论标签吗?
    • 我现在这样做了,它显示标签但没有评论标签
    • 我建议您检查 html 以查看它是否确实丢失,或者是否存在导致其无法显示的 css 问题。如果它不在 html 中,表明没有按照上面第 1 步所述打开评论,或者没有按照上面第 2 步为产品启用评论,或者插件或您的主题中的某处代码正在删除它从标签列表中,即通过 woocommerce_products_tabs 过滤器。
    • 我已经检查了元素并且评论标签不存在。我也跟着第一步,勾选了复选框,应该可以工作,但我不知道为什么它不工作。能否请您与 TeamViewer 联系并帮助我找出问题所在。我永远不会忘记这个恩惠,谢谢
    猜你喜欢
    • 1970-01-01
    • 2021-12-04
    • 2013-06-05
    • 2019-03-10
    • 1970-01-01
    • 2014-09-09
    • 1970-01-01
    • 2017-09-15
    • 2012-06-30
    相关资源
    最近更新 更多