我们需要传递以下WooCommerce参数,但我们不能并且有错误。
- 唯一订单编号
- 购买的产品 SKU
- 购买的每种产品的数量
- 购买的每种产品的价格
- 交易货币
- 折扣金额(整单和特定商品(
- 使用的优惠券代码
主要问题是获取所有产品的数量,购买的每个产品的数量,产品SKU
这是我们的代码:
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;
}
但它并没有给我们带来我们应该需要的预期结果。
任何帮助,不胜感激。
现在要获取丢失的订单"行项目"详细信息和订单详细信息,这是正确的方法:
add_action( 'woocommerce_thankyou', 'the_tracking' );
function the_tracking( $order_id ) {
$count = 0;
$order = wc_get_order( $order_id );
// Starting tracking line
$tracking = 'OrderID='. $order_id;
foreach( $order->get_items() as $item_id => $item ){
// Get an instance of the WC_Product object
$product = $item->get_product();
$product_sku = $product->get_sku(); // Item product SKU
$item_qty = $item->get_quantity(); // Item Quantity
$item_subtotal_tax = $item->get_subtotal_tax(); // Item subtotal tax
$item_subtotal = $item->get_subtotal(); // Item subtotal
$item_total_tax = $item->get_total_tax(); // Item Total tax discounted
$item_total = $item->get_total(); // Item Total discounted
// Tracking line for each item (continuation)
$tracking .= "&ITEM{$count}={$product_sku}&AMT{$count}={$item_total}&QTY{$count}={$item_qty}";
$count++; // increment the item count
}
// Tracking line (continuation) ====> ??? CID, OID and TYPE
$tracking .= "&CID=1529328&OID=[OID]&TYPE=385769";
// An order can have no used coupons or also many used coupons
$coupons = $order->get_used_coupons();
$coupons = count($coupons) > 0 ? implode(',', $coupons) : '';
$discount = $order->get_total_discount();
$currency = $order->get_currency();
$subtotal = $order->get_subtotal();
$total = $order->get_total();
// Tracking line (end)
$tracking .= "&AMOUNT={$total}&DISCOUNT={$discount}&CURRENCY={$currency}&COUPON={$coupons}";
echo $tracking;
}
代码进入函数.php活动子主题(或活动主题(的文件。经过测试并工作。
您必须在跟踪文档中查看用途:
CID
,OID
和TYPE
...