简体   繁体   English

在WooCommerce中显示正常价格之前的促销价格

[英]Display the Sale price before Regular price in WooCommerce

I am a new member and is weak in programer. 我是新成员,在程序员方面很弱。 I want display Sale price before Regular price (as images attach). 我希望在正常价格之前显示销售价格(如附图所示)。 I determined the hook here is woocommerce_before_variations_form. 我确定这里的钩子是woocommerce_before_variations_form。 Here is the code to edit in the hook. 这是在钩子中编辑的代码。

// define the woocommerce_before_variations_form callback
function action_woocommerce_before_variations_form () {
     // make action magic happen here ...
};
         
// add the action
add_action ('woocommerce_before_variations_form', 'action_woocommerce_before_variations_form', 10, 0);

图片

Can you help me display Sale price before Regular price? 你能帮我在正常价格之前显示促销价吗?

The following hooked function code will display the Sale price before Regular price: 以下挂钩功能代码将显示正常价格之前的促销价:

add_filter( 'woocommerce_format_sale_price', 'invert_formatted_sale_price', 10, 3 );
function invert_formatted_sale_price( $price, $regular_price, $sale_price ) {
    return '<ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . '</ins> <del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del>';
}

Code goes in function.php file of the active child theme (or active theme). 代码位于活动子主题(或活动主题)的function.php文件中。 Tested and works. 经过测试和工作。

You can solve this using only jQuery and swap to element that show the regular price and sale price: 你可以只使用jQuery解决这个问题,并交换到显示常规价格和销售价格的元素:

$("#element1").before($("#element2"));

or 要么

$("#element1").after($("#element2"));

:) :)

and one more on js fiddle https://jsfiddle.net/nak73406/v9k7b5c1/5/ 还有一个关于js小提琴https://jsfiddle.net/nak73406/v9k7b5c1/5/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM