在 WooCommerce 中的正常价格之前显示销售价格
Display the Sale price before Regular price in WooCommerce
我是新人,程序员比较弱。我想在正常价格之前显示销售价格(如图片所示)。
我确定这里的钩子是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);
你能帮我在正常价格之前显示促销价吗?
您可以仅使用 jQuery 并切换到显示正常价格和销售价格的元素来解决此问题:
$("#element1").before($("#element2"));
或
$("#element1").after($("#element2"));
:)
and one more on js fiddle
https://jsfiddle.net/nak73406/v9k7b5c1/5/
以下钩子函数代码将在正常价格之前显示促销价:
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 文件。已测试并有效。
我是新人,程序员比较弱。我想在正常价格之前显示销售价格(如图片所示)。 我确定这里的钩子是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);
你能帮我在正常价格之前显示促销价吗?
您可以仅使用 jQuery 并切换到显示正常价格和销售价格的元素来解决此问题:
$("#element1").before($("#element2"));
或
$("#element1").after($("#element2"));
:)
and one more on js fiddle https://jsfiddle.net/nak73406/v9k7b5c1/5/
以下钩子函数代码将在正常价格之前显示促销价:
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 文件。已测试并有效。