向显示总价的 WooCommerce 订单添加文本
Add a text to WooCommerce orders displayed total price
通过以下挂钩,我将文本添加到总价格中:
add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_total_message_html', 10, 1 );
function custom_total_message_html( $value ) {
$text_to_add_before_price = 'excl. BTW '; //change text in quotes to your preferred text
return $text_to_add_before_price . $value;
}
只有我看到感谢页面上没有显示 table。是否可以仅在 'total' 行中为价格添加文本?
示例中为:20.35 欧元,但这应该是 20.35 欧元,不含税。增值税。使用当前挂钩,这仅在购物车和结帐页面中完成
对于订单 (和电子邮件通知) 使用以下命令在订单总行之前添加自定义文本:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_line_html', 1000, 3 );
function custom_order_total_line_html( $total_rows, $order, $tax_display ){
$total_rows['order_total']['value'] = __('excl. BTW ') . ' ' . $total_rows['order_total']['value'];
return $total_rows;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
要在之后添加它,请使用:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_line_html', 1000, 3 );
function custom_order_total_line_html( $total_rows, $order, $tax_display ){
$total_rows['order_total']['value'] .= ' ' . __('excl. BTW ');
return $total_rows;
}
通过以下挂钩,我将文本添加到总价格中:
add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_total_message_html', 10, 1 );
function custom_total_message_html( $value ) {
$text_to_add_before_price = 'excl. BTW '; //change text in quotes to your preferred text
return $text_to_add_before_price . $value;
}
只有我看到感谢页面上没有显示 table。是否可以仅在 'total' 行中为价格添加文本?
示例中为:20.35 欧元,但这应该是 20.35 欧元,不含税。增值税。使用当前挂钩,这仅在购物车和结帐页面中完成
对于订单 (和电子邮件通知) 使用以下命令在订单总行之前添加自定义文本:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_line_html', 1000, 3 );
function custom_order_total_line_html( $total_rows, $order, $tax_display ){
$total_rows['order_total']['value'] = __('excl. BTW ') . ' ' . $total_rows['order_total']['value'];
return $total_rows;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
要在之后添加它,请使用:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_line_html', 1000, 3 );
function custom_order_total_line_html( $total_rows, $order, $tax_display ){
$total_rows['order_total']['value'] .= ' ' . __('excl. BTW ');
return $total_rows;
}