我使用它来在购物车和结帐页面上为来自特定国家/地区的客户显示自定义文本:
add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_total_message_html', 10, 1 );
function custom_total_message_html( $value ) {
if( in_array( WC()->customer->get_shipping_country(), array('US', 'CA') ) ) {
$value .= '<small>' . __('My text.', 'woocommerce') . '</small>';
}
return $value;
}
但是,这不会在Woocommerce发送的普通订单电子邮件中的订单总计之后添加自定义文本。我知道有一个过滤器,woocommerce_get_formatted_order_total
但是我似乎无法使用它。如何修改上面的功能,以便在普通订单电子邮件中的价格之后显示自定义文本?
要在总计之后在WooCommerce订单和电子邮件中显示此自定义文本,请使用以下命令:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_message_html', 10, 3 );
function custom_order_total_message_html( $total_rows, $order, $tax_display ) {
if( in_array( $order->get_shipping_country(), array('US', 'CA') ) && isset($total_rows['order_total']) ) {
$total_rows['order_total']['value'] .= ' <small>' . __('My text.', 'woocommerce') . '</small>';
}
return $total_rows;
}
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试和工作。
要使其仅在电子邮件通知上起作用,请使用:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_message_html', 10, 3 );
function custom_order_total_message_html( $total_rows, $order, $tax_display ) {
if( in_array( $order->get_shipping_country(), array('US', 'CA') ) && isset($total_rows['order_total']) && ! is_wc_endpoint_url() ) {
$total_rows['order_total']['value'] .= ' <small>' . __('My text.', 'woocommerce') . '</small>';
}
return $total_rows;
}
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试和工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句