Change price location on single product pages

隐身守侯 提交于 2019-12-11 04:48:39

问题


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.

Page link for a product is here

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?

Thanks


回答1:


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

This is the code you need:

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

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

The code is tested and works.



来源:https://stackoverflow.com/questions/42513624/change-price-location-on-single-product-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!