更改单个产品页面上的评论评级位置

Change the review rating location on single product pages

实际上,在 WooCommerce 中,我正在使用 来更改我的简单产品的价格位置:

function changing_price_location_for_simple_products(){
    global $product;

    if($product->is_type('simple')) // Only for simple products (thanks to helgathevicking)
    {
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
        add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 25);
    }
}
add_action('woocommerce_before_single_product', 'changing_price_location_for_simple_products');

我想将评论中的星级评分从页面顶部向下移动到我的价格上方或右侧。

这里是live link to a product

请问有什么帮助吗?

谢谢

如果你打开template woocommerce file content-single-product.php,你会在里面看到:

    /**
     * woocommerce_single_product_summary hook.
     *
     * @hooked woocommerce_template_single_title - 5
     * @hooked woocommerce_template_single_rating - 10
     * @hooked woocommerce_template_single_price - 10
     * @hooked woocommerce_template_single_excerpt - 20
     * @hooked woocommerce_template_single_add_to_cart - 30
     * @hooked woocommerce_template_single_meta - 40
     * @hooked woocommerce_template_single_sharing - 50
     */
    do_action( 'woocommerce_single_product_summary' );

因此,这向您展示了在 woocommerce_single_product_summary 操作挂钩中挂钩的不同模板及其优先级(末尾的小数字)。

所以你可以 并用这个替换它:

function customizing_simple_products(){
    global $product;

    if($product->is_type('simple')) // Only for simple products (thanks to helgathevicking)
    {
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10); 
        add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 25);
        add_action('woocommerce_single_product_summary', 'woocommerce_template_single_rating', 26); 
    }
}
add_action('woocommerce_before_single_product', 'customizing_simple_products');

并且您需要在活动主题 style.css 中添加一些 CSS 规则(最好使用儿童theme) 以获得与此评级并排的产品价格。为此,您必须定位正确的选择器,有时您将不得不向该规则添加 !important 以使其生效。如果需要,您还可以在我的回答功能中操纵优先级数字……

代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。

代码已经过测试并且有效。