Search code examples
phpwordpresswoocommercehook-woocommercereview

Move single product stars rating in WooCommerce


I am learning WooCommerce development. I would like to display the stars rating at top of the heading so I tried like this (Not a review, it's just an example):

 function action_woocommerce_single_product_review() {
      //I don't want to show any content here    
 } 
  add_action( 'woocommerce_single_product_summary', 'action_woocommerce_single_product_review', 1, 0 ); 

I also tried using jQuery which is working:

$(".woocommerce-product-rating").insertBefore('.product_title'); 

Solution

  • To move stars ratings before product title in single product pages use:

    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
    
    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 3 );
    

    Code goes in functions.php file of the active child theme (or active theme). Tested and works.

    Related: WooCommerce action hooks and overriding templates