我尝试将0欧元的价格替换为结帐页面和电子邮件中的小计和小计,但是没有成功!
@LoicTheAztec将此代码发布到Replace product zero displayed price with a custom text in Woocommerce 3上,该代码通过自定义文本对显示价格的产品/商品非常有用:
// Order items displayed prices (and also email notifications)
add_filter( 'woocommerce_order_formatted_line_subtotal', 'free_order_item_price_custom_label', 20, 3 );
function free_order_item_price_custom_label( $subtotal, $item, $order ) {
// HERE your custom free price label
$free_label = '<span class="amount">' . __('Based on contract') . '</span>';
if( $order->get_line_subtotal( $item ) > 0 )
return $subtotal;
else
return $free_label;
}
我还看到了@radug发布的WooCommerce: Cart price override with text,它起作用了,但是代码更改了所有价格,实际上,总计和小计被正确替换了,但是在所有不为0的字段甚至字段上都被替换了。 >
add_filter( 'woocommerce_order_formatted_line_subtotal', 'filter_order_item_subtotal', 10, 3 );
function filter_order_item_subtotal( $subtotal, $item, $order ) {
if ( isset( $item[ 'line_subtotal' ] ) && $item[ 'line_subtotal' ] == 0 ) {
$subtotal = __( 'To be determined 2', 'yourtheme' );
}
return $subtotal;
}
add_filter( 'woocommerce_order_subtotal_to_display', 'filter_woocommerce_order_subtotal_to_display', 10, 3 );
function filter_woocommerce_order_subtotal_to_display( $subtotal, $compound, $instance ) {
$subtotal = __( 'To be determined 6', 'yourtheme' );
return $subtotal;
};
add_filter( 'woocommerce_get_formatted_order_total', 'filter_woocommerce_get_formatted_order_total', 10, 2 );
function filter_woocommerce_get_formatted_order_total( $formatted_total, $instance ) {
$formatted_total = __( 'To be determined 8', 'yourtheme' );
return $formatted_total;
};
您能帮助我理解为什么所有订单上的所有0欧元价值都发生变化并请解决我的麻烦吗?