Categories: WooCommerce Tricks

Move Reviews tab before the description on WooCommerce product pages

Here, We explain how to move ‘Reviews’ tab to first position among ‘description’ and ‘additional information’ tabs on a WooCommerce website. By this we can give more visibility to reviews. We have already posted a code that shows reviews separately out of the tabs section. Now, lets move the ‘Reviews’ tab position in the tabs section on WooCommerce product pages.

Place to add this Code: On WordPress Dashboard, hover on Appearance > Theme Editor and open the functions.php file. Add the following code at the end.

add_filter( 'woocommerce_product_tabs', 'wpd_wc_move_product_review_tab', 1005 );
/**
 * Move Reviews tab before Description tab
 *
 * @param array $tabs Array of tabs.
 * @return array
 */function wpd_wc_move_product_review_tab( $tabs ) {
 global $product, $post;

 $new_tabs = array();

 if ( comments_open() ) {
  $new_tabs['reviews'] = $tabs['reviews'];
  unset( $tabs['reviews'] );

  if ( $post->post_content ) {
   $new_tabs['description'] = $tabs['description'];
   unset( $tabs['description'] );
  }

  if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
   $new_tabs['additional_information'] = $tabs['additional_information'];
   unset( $tabs['additional_information'] );
  }

  $tabs = array_merge( $new_tabs, $tabs );
 }

 return $tabs;
}

Under WooCommerce filters, we can add/edit/delete the existing tabs with the woocommerce_product_tabs filter. So first we have to check whether Reviews Tab is active or not.

Here, First,we are creating a new tabs array variable to check whether reviews form is active or not (use if it is necessary). If reviews form is active, then we can re-position each tab accordingly.

  • 14-15: Assigning the existing reviews tab at first place in new tabs array and removing the existing reviews tab from the old tabs array.
  • 17-20: If a product has Description tab, we assign the old description tabs at 2nd place in the new tabs array and removing it from the old tabs array.
  • 22-25: If a product has Additional Information tab, we assign this tab the 3rd place in the new tabs array and remove it from the old tabs array.
  • 27: Merging two arrays and creating a new array.
  • 30: Returning array for the display.

After updating this code to your functions.php, you can see that reviews tab is moved to first position and this helps you to gain more reviews and ratings.

Vinod Katrela

Share
Published by
Vinod Katrela

Recent Posts

How to Disable Plugin Updates in WordPress

Some of our readers asked us how to disable plugin updates in WordPress? Earlier there…

4 years ago