您正在搜索的钩子是 woocommerce_email_order_details 可以这样使用的动作钩子:
add_action( 'woocommerce_email_order_details', 'action_email_order_details', 10, 4 );
function action_email_order_details( $order, $sent_to_admin, $plain_text, $email ) {
if( $sent_to_admin ): // For admin emails notification
// Your code goes HERE
endif;
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
在您的函数中,您可以使用来自钩子的 4 个参数中的任何一个,例如 $order 和 WC_Order 对象。
您可以使用WC_Abstract_Order 方法get_used_coupons() 为您提供订单中使用的一系列优惠券代码,例如:
// Get the array of coupons codes
$coupon_codes = $order->get_used_coupons();
// Convert and display the array in a coma separated string:
echo 'Coupon codes: ' . implode( ', ', $coupon_codes );