-1

I am working in e-commerce website, i made my own theme and I installed the woocommerce plugin. but there is a problem displaying the products reviews.

the code below is in the 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; ?>

I have spent the past 2 days in this problem and couldn't figure out why its not showing the reviews

zero cool
  • 9
  • 5

1 Answers1

1

In order to display the Product Reviews you need to ensure a couple of things

  1. In WooCommerce --> Settings on the Products tab under General, ensure that you have ticked "Enable product reviews"
  2. In the actual products under "Advanced" tick "Enable reviews"
  3. Also when setting up a custom theme if you are overriding the default template for single product you need to ensure that you include the woocommerce_after_single_product_summary action as it includes the woocommerce_output_product_data_tabs that includes displaying the product Reviews
    /**
     * 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' );

Here's a link to an article with images explaining steps 1 and 2 further Reviews not showing on product page

jtowell
  • 246
  • 1
  • 2
  • 8
  • 1
    this also not working. I have tried that but its not displaying it. but if i write comments_template() it shows the comments dublicated and not where i want it to be – zero cool Jan 19 '22 at 04:18
  • I can see that you have customised woocommerce/single-product/tabs/tabs.php which when I try it causes the review tab to appear twice, once as "Reviews (x)" and again "Reviews". What happens if you remove your customised file from the theme and use the default woocommerce one, which will by default display the Reviews tab if you have it set as per step 1 above. Do you then see the reviews tab? – jtowell Jan 20 '22 at 05:43
  • i did that now its displaying the tabs but with no reviews tab – zero cool Jan 20 '22 at 21:47
  • I suggest you inspect the html to see if it is in fact missing, or if there is a css issue making it not display. If it is not in the html that suggests that either reviews have not been turned on as mentioned in step 1 above, or not enabled for the product as in step 2 above or there is code somewhere in a plugin or your theme that is removing it from the tabs list ie via the woocommerce_products_tabs filter. – jtowell Jan 22 '22 at 00:52
  • I have inspected element and the review tab doesn't exist. and I followed step one and too and the checkboxes are ticked and should be working but i dont know why its not working. can you please Connect with TeamViewer and help me work out whats wrong. I will never forget this favour thank you – zero cool Jan 23 '22 at 18:30