John Davidson

php - Woocommerce review section outside of tab (on single-product page) wont' show comments?

0 comments
Message:


I am working on a custom theme, so what I have done so far is:



  1. I removed the review tab in the Woocommerce single product page because I replaced it with 5 custom tabs and I want to write my custom section just below ('woocommerce_after_single_product_summary').

  2. I copied the 'single-product-reviews.php' template for editing and called it in my theme's functions file. That all seems to work fine.
    This is how it looks.


As you can see everything reads fine except for the comments themselves. There are reviews/comments posted, I tested it multiple times manually and from Dashboard, I just can't get them to show up. The star rating shows up on the products themselves, even on the shop page after you write the review, so it obviously works. It might be a simple mistake, I might just be too tired to notice it. I will post the code, if anyone has any solutions, thanks in advance.


Btw the reviews and comments are enabled everywhere in the Dashboard, I checked it many times. This is the div/code that is causing the problem, I have not edited the file at all besides changing the title.


    <?php if ( have_comments() ) : ?>
<ol class="commentlist">
<?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments' ) ) ); ?>
</ol>

<?php
if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
echo '<nav class="woocommerce-pagination">';
paginate_comments_links(
apply_filters(
'woocommerce_comment_pagination_args',
array(
'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
'next_text' => is_rtl() ? '&larr;' : '&rarr;',
'type' => 'list',
)
)
);
echo '</nav>';
endif;
?>
<?php else : ?>
<p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'woocommerce' ); ?></p>
<?php endif; ?>
</div>


My Answer:
display

To display the Woocommerce review section outside of the tab on the single-product page, you can use the following code snippet:

php
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );


This code will display the review section outside of the tab on the single-product page. You can add this code to your theme's functions.php file or create a custom plugin for it.

Make sure to test this code on a staging site before implementing it on your live site to avoid any issues.

Rate this post

3 of 5 based on 2256 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us