简体   繁体   中英

Woocommerce coupon codes

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/

The solution seems to change:

add_action('woocommerce_new_order', 'myfunction');

Into:

add_action('woocommerce_thankyou', 'myfunction');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM