我制作了以下函数来接收订单的cart total、order_id和优惠券代码。该功能显示购物车的总金额和订单id,但不显示应用的优惠券代码。
add_action('woocommerce_new_order', 'myfunction');
function myfunction($order_id) {
global $woocommerce;
// cart total
$cart_total = $woocommerce->cart->total;
// order id
$order = new WC_Order($order_id);
$order_id = $order->get_order_number();
// coupons
$coupons = '';
foreach($order->get_used_coupons() as $coupon) {
$coupons .= $coupon;
}
}
根据Wooccommerce编码的例子,它应该起作用:http://docs.woothemes.com/document/send-coupons-used-in-an-order-by-email/
解决方案似乎发生了变化:
add_action('woocommerce_new_order', 'myfunction');
进入:
add_action('woocommerce_thankyou', 'myfunction');