From 2a4bfc2af15f677d8fb49a6be83d6ea9a1818c17 Mon Sep 17 00:00:00 2001 From: Davod Saraei Date: Sun, 25 Jul 2021 11:16:34 +0430 Subject: [PATCH] fix bug in get coupon in woo3 --- classes/Woocommerce.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/classes/Woocommerce.php b/classes/Woocommerce.php index 4e7d353..de6ce65 100644 --- a/classes/Woocommerce.php +++ b/classes/Woocommerce.php @@ -105,8 +105,14 @@ public function getOrderData($order) $options['meta_data'][$key] = $line_item; } - if($coupons = $order->get_coupon_codes()) { - $options['coupon'] = array_values($coupons)[0] ?? ''; + if ($this->isWoo3()) { + if ($coupons = $order->get_data()['coupon_lines']) { + $options['coupon'] = array_values($coupons)[0]->get_code() ?? ''; + } + } else { + if ($coupons = $order->get_coupon_codes()) { + $options['coupon'] = array_values($coupons)[0] ?? ''; + } } $external_id = $this->isWoo3() ? $order->get_id() : $order->id;