We need pass these following WooCommerce parameters but we can't and have got errors.
- Unique Order ID
- Product SKUs purchased
- Quantity of each product purchased
- Price of each product purchased
- Currency of the transaction
- Discount Amount (whole-order and item-specific)
- Coupon Code used
the main issues are getting all products Quantities, Quantity of each product purchased, Product SKU
Here is our code:
add_action( 'woocommerce_thankyou', 'the_tracking' );
function the_tracking( $order_id ) {
global $woocommerce;
$order = wc_get_order( $order_id );
$total = $order->get_total();
$currency = get_woocommerce_currency();
$subtotal = $woocommerce->cart->subtotal;
$coupons = $order->get_used_coupons();
$coupon_code = '';
$discount = $order->get_total_discount();
foreach ($coupons as $coupon){
$coupon_code = $coupon;
}
$tracking = 'OrderID='.$order.'&ITEMx=[ItemSku]&AMTx=[AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT='. $total .'&DISCOUNT='. $discount .'&CURRENCY='. $currency .'&COUPON='. $coupon_code .'';
echo $tracking;
}
But it doesn't give us the expected results as we should need.
Any help is appreciated.