更改单个产品页面上的价格位置 [英] Change price location on single product pages

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

问题描述

这是我一直在思考的事情,我似乎无法在这里找到我想要的东西.

This is something that has been doing my head in and I can't seem to find exactly what I want on here.

我正在尝试将产品页面上的价格移动到添加到购物车按钮的正上方或旁边.

I am trying to move the price on my product pages to display just above or beside the add to cart button.

产品的页面链接在这里

我以前玩过这个,并设法在我想要的位置上创建了第二个价格,但仍然有原始价格在顶部并且无法摆脱它.

I have played around with this before, and managed to create a second price in the position I wanted, but still had the original price at the top and couldn't get rid of it.

我怎样才能做到这一点?

How can I achieve this?

谢谢

推荐答案

这仅适用于简单产品,因为可变产品已在添加到购物车"按钮上方显示其实时价格.

This will work just for simple products as variable products displays already their live price above the Add-to-cart button.

这是您需要的代码:

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

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

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

The code is tested and works.

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

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