2014-10-01 204 views
1

我使用以下功能來接收訂單的購物車總額,訂單ID和優惠券代碼。該功能顯示購物車的總金額和訂單ID,但不顯示應用的優惠券代碼。Woocommerce優惠券代碼

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; 
     } 
} 

按照Woocommerce手抄本例如,它應該工作: http://docs.woothemes.com/document/send-coupons-used-in-an-order-by-email/

回答

2

的解決方案似乎改變:

add_action('woocommerce_new_order', 'myfunction'); 

分爲:

add_action('woocommerce_thankyou', 'myfunction');