1

I'm trying to pass a few order details to a third party on the Woocommerce thankyou page. Everything works fine—except getting the coupon ID.

What am I missing? I've read through this question, but didn't illuminate the subject too much.

Doesn't seem like a lot of documentation on WC coupons... Thanks!

function goodcart_tracking( $order_id ) {

    $order = new WC_Order( $order_id );
    $order_number = $order->get_id();
    $currency = $order->get_order_currency();
    $email = $order->get_billing_email();
    $total = $order->get_total();
    $coupon = $order->get_used_coupons().implode(",",$coupons);
    $date = $order->order_date;
?>

    <script type="text/javascript">
        var params = {
            'gc_hash': 'HASH_ID',
            'customer_email': '<?php echo $email ?>',
            'order_id': '<?php echo $order_number; ?>',
            'order_amount': '<?php echo $total; ?>',
            'order_amount_type': '<?php echo $currency; ?>',
            'promo_code': '<?php echo $coupon; ?>'
        };
        iGCCpnObj = new _iGCBannerObj(params); iGCCpnObj.start();
  </script>
<?php  } 
Luke Finsaas
  • 63
  • 1
  • 6

1 Answers1

1

Assuming this can help you further

$order = new WC_Order( $order_id );

$coupons = $order->get_used_coupons();

foreach( $coupons as $coupon ){

    // Coupon id
    $coupon_post_object = get_page_by_title($coupon, OBJECT, 'shop_coupon');
    $coupon_id          = $coupon_post_object->ID;

    echo $coupon_id . '<br>';

    // Coupon object
    $coupon_object = new WC_Coupon($coupon_id);

    // echo...
    echo $coupon_object->get_code() . '<br>';
    //etc...
    // view: https://docs.woocommerce.com/wc-apidocs/class-WC_Coupon.html
}
7uc1f3r
  • 28,449
  • 17
  • 32
  • 50