首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >woocommerce -向订单页面添加跟踪代码(commision junction affiliate计划

woocommerce -向订单页面添加跟踪代码(commision junction affiliate计划
EN

Stack Overflow用户
提问于 2016-05-20 04:20:02
回答 2查看 623关注 0票数 1

我希望整合从从属计划委员会交界处跟踪。

他们已经为我提供了以下示例代码,以添加到我的订单接收页面,任何有关如何将此放置在/订单接收/端点及其要求的修改方面的帮助都将不胜感激。我完全迷路了,有几个类似程序的插件。

(如果有帮助的话,他们提供了javascript和asp的替代方案)

代码语言:javascript
复制
<!-- BEGIN COMMISSION JUNCTION TRACKING CODE -->

<iframe height="1" width="1" frameborder="0" scrolling="no"         src="https://www.emjcd.com/tags/c?containerTagId=14209&ITEMx=[ItemSku]&AMTx=    [AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT=[Subtotal]&DISCOUNT=[DiscountAmount]&CURRENCY=[CURRENCY]&COUPON=[couponcode]" name="cj_conversion" ></iframe>

<!-- END COMMISSION JUNCTION TRACKING CODE -->
EN

回答 2

Stack Overflow用户

发布于 2016-05-20 07:24:32

在您的主题functions.php文件中添加以下代码

代码语言:javascript
复制
add_action( 'woocommerce_thankyou', 'my_custom_tracking' );

function my_custom_tracking( $order_id ) {

    global  $woocommerce;

    $order = wc_get_order( $order_id );
    $total = $order->get_total();
    $currency = get_woocommerce_currency();

    $coupons = $order->get_used_coupons();

    $coupon_code = '';

    foreach ($coupons as $coupon){
        $coupon_code = $coupon;
    }

    $discount = $order->get_total_discount();

    $tracking = '<iframe height="1" width="1" frameborder="0" scrolling="no" src="https://www.emjcd.com/tags/c?containerTagId=14209&ITEMx=[ItemSku]&AMTx=[AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT='. $total .'&DISCOUNT='. $discount .'&CURRENCY='. $currency .'&COUPON='. $coupon_code .'" name="cj_conversion" ></iframe>';
    echo $tracking;

    }

查看您的跟踪代码,我猜我们可能需要用正确的值填充src url。但我不确定。

票数 0
EN

Stack Overflow用户

发布于 2016-05-21 08:00:53

您需要列出所有购买的SKU及其价格。如果需要,您可以使用DISCOUNT参数对订单应用美元折扣,除非您已经在iframe中输入的价格中扣除了折扣。优惠券代码也是一个不错的选择。

如果你想在JavaScript中做到这一点,并且假设你的订单数据在一个看起来像下面的虚拟数据的对象数组中,下面是你如何在JavaScript中做到这一点的:

代码语言:javascript
复制
// Some dummy data (populate real data in your code)
var order = {
	id: "AB12345",
	subtotal: "200.00",
	discount: "10.00",
	coupon: "DEAL10",
	items: [
		{ sku: "FOO123", price: "75.00", quantity: 2 },
		{ sku: "BAR234", price: "50.00", quantity: 1 }
	]
};

// The actual code
var cj = {
	tagId: 14209,
	cid: 1529328,
	type: 385769
};
var cjString = "https://www.emjcd.com/tags/c?containerTagId=" + cj.tagId + "&";

for (i=0; i<order.items.length; i++) {
  cjString += "ITEM" + i + "=" order.items[i].sku + "AMT" + i + order.items[i].price + "QTY" + i + order.items[i].quantity + "&";
}

cjString += "CID=" + cj.cid + "&OID=" + order.id + "&TYPE=" + cj.type + "&AMOUNT=" + order.subtotal + ( discount.length ? "&DISCOUNT=" + order.discount : "" ) + "&CURRENCY=USD" + ( coupon.length ? "&COUPON=" + order.coupon : "" );

// Now we put it all together and insert into the page
var frame = document.createElement("iframe");
frame.name = "cj_conversion";
frame.height = 1;
frame.width = 1;
frame.frameBorder = 0;
frame.scrolling = "no";
frame.src = cjString;
document.body.insertBefore(frame, document.body.childNodes[0]);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37333253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档