1
votes

I made the following function to receive the cart total, order_id and coupon codes of an order. The function shows the total amount of the cart and the order id, but does not show the applied coupon codes.

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

According to the Woocommerce codex example it should work: http://docs.woothemes.com/document/send-coupons-used-in-an-order-by-email/

1

1 Answers

3
votes

The solution seems to change:

add_action('woocommerce_new_order', 'myfunction');

Into:

add_action('woocommerce_thankyou', 'myfunction');