更改单个产品页面上的评论评级位置 [英] Change the review rating location on single product pages

查看:38
本文介绍了更改单个产品页面上的评论评级位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,在 WooCommerce 中,我使用的是下面的代码,更改我的简单产品的价格位置:

Actually, In WooCommerce, I am using the code below, to change the price location for my simple products:

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

我想将评论中的星级从页面顶部向下移动,以显示在我的价格上方或右侧.

I would like to move the star rating from reviews down from the top of the page to appear above or to the right of my price.

这里是产品的实时链接

请问,有什么帮助吗?

谢谢

推荐答案

如果您打开 模板 woocommerce 文件 content-single-product.php,你会在里面看到:

If you open the template woocommerce file content-single-product.php, you will see that inside:

    /**
     * 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 操作挂钩中挂钩的不同模板及其优先级(末尾的小数字).

So this show you the different templates hooked in woocommerce_single_product_summary action hook with their priorities (the little number at the end).

这样你就可以重用我的代码 并用这个替换它:

So you can reuse my code and replace it with this one:

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 规则(最好使用子主题)将产品价格与此评级并列.为此,您必须针对正确的选择器,有时您必须将 !important 添加到该规则中,以使其有效.如果需要,您还可以在我的回答功能中操作优先级数字...

And you will need to add some CSS rules in the style.css of your active theme (is better use a child theme) to get the product price side by side with this ratings. For this you have to target the correct selectors and sometimes you will be obliged to add !important to that rules, to make them effective. You can also manipulate the priority numbers if needed in my answer function…

代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.

代码已经过测试并且可以正常工作.

The code is tested and works.

这篇关于更改单个产品页面上的评论评级位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆