在 WooCommerce 中移动单个产品星级

问题描述

我正在学习 WooCommerce 开发。我想在标题顶部显示星级,所以我尝试这样(不是评论,这只是一个例子):

 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 ); 

我也尝试过使用 jQuery,它是有效的:

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

解决方法

要在单个产品页面中的产品标题之前移动星级评级,请使用:

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

add_action( 'woocommerce_single_product_summary',3 );

代码位于活动子主题(或活动主题)的functions.php 文件中。经测试有效。

相关:WooCommerce action hooks and overriding templates