且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Woocommerce 订单和电子邮件中的订单总额后添加自定义文本

更新时间:2023-10-14 17:31:46

要在 WooCommerce 订单和电子邮件中显示此自定义文本,请使用以下内容:

For displaying this custom text in WooCommerce orders and emails after total, use the following:

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 文件中.经测试有效.

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

要使其仅适用于电子邮件通知,请使用:

To make it work only on email notifications use:

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 文件中.经测试有效.

Code goes in functions.php file of the active child theme (or active theme). Tested and works.