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

问题描述 投票:4回答:2

我是新成员,在程序员方面很弱。我希望在正常价格之前显示销售价格(如附图所示)。我确定这里的钩子是woocommerce_before_variations_form。这是在钩子中编辑的代码。

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

images

你能帮我在正常价格之前显示促销价吗?

php wordpress woocommerce product price
2个回答
4
投票

以下挂钩功能代码将显示正常价格之前的促销价:

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

代码位于活动子主题(或活动主题)的function.php文件中。经过测试和工作。


1
投票

你可以只使用jQuery解决这个问题,并交换到显示常规价格和销售价格的元素:

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

要么

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

:)

还有一个关于js小提琴https://jsfiddle.net/nak73406/v9k7b5c1/5/

© www.soinside.com 2019 - 2024. All rights reserved.