don*_*sys 5 php wordpress product woocommerce price
我是新成员,编程能力较弱。我想在正常价格之前显示销售价格(如附图所示)。我确定这里的钩子是 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);
Run Code Online (Sandbox Code Playgroud)
你能帮我在正常价格之前显示销售价格吗?
以下挂钩函数代码将在常规价格之前显示销售价格:
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>';
}
Run Code Online (Sandbox Code Playgroud)
代码位于活动子主题(或活动主题)的 function.php 文件中。测试和工作。
| 归档时间: |
|
| 查看次数: |
3838 次 |
| 最近记录: |