Opens in a new tab

Premium add-on for Bricks Builder

Move the Reviews tab before the Description tab on the single product page

Displays the Reviews tab as the first tab on the single product page. Add the following PHP code inside the Bricks’ code block element.

Preview: Before and After

Repositioning the Reviews tab

PHP Snippets: Move Reviews Tab

Open the single product page template on bricks builder editor and add the Code element at the top position.

Code block element

Enter the following PHP code and enable the “Execute Code” option.[edd_restrict id=”12,14″ message=”If you want to view the rest of the content, you need to buy the BricksUltimate add-on. Users of the BricksUltimate will view this content after login.”]

<?php
add_filter( 'woocommerce_product_tabs', 'bu_wc_move_product_review_tab', 1005 );
/**
 * Move Reviews tab before Description tab
 *
 * @param array $tabs Array of tabs.
 * @return array
 */
function bu_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;
}
?>

The Code Explanation

You can filter (add/edit/delete) the existing tabs with the woocommerce_product_tabs filter. First, I am creating a new tabs array variable and then checking if the reviews form is open for a product. If the review form is open, then we are re-positioning specific tabs.

  • 15-16: Re-assigning the existing reviews tab at first place in new tabs array and removing the existing reviews tab from the old tabs array.
  • 18-21: 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.
  • 23-26: 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.
  • 28: Merging two arrays and creating a new array.
  • 31: Returning array for the display.[/edd_restrict]