php - 在 Woocommerce 订单和电子邮件中的订单总额后添加自定义文本
问题描述
我正在使用它在购物车和结帐页面上为来自特定国家/地区的客户显示自定义文本:
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 文件中。测试和工作。
推荐阅读
- angular - 将带有 rxjs 的 Angular 5 模块导入 Angular 8 应用程序
- ios - Firebase Firestore collectionGroup()查询方法无法识别 - swift
- acumatica - 如何在报表设计器中通过 URL 引用外部图像?
- php - MySQL阻止用户从其他用户那里获取代码
- excel - 在单元格中搜索特定文本并从列表中返回匹配的文本
- kotlin - Kotlin 结合使用箭头、lamda、?、. , 然后让。什么意思?
- python - Pandas to_sql 设置列类型
- c# - 您可以将事件附加到您无法修改的属性吗?
- ruby-on-rails - 未知键::表达式。有效键是::unique、:order、:name、:where、:length、:internal、:using、:algorithm、:type
- javascript - Javascript - 仅在设备处于横向时显示 div