Woocommerce感谢页面中的Linkwise会员集成 [英] Linkwise Affiliate integration in Woocommerce thankyou page
问题描述
我有一个Woocommerce商店,我想将订单完成数据发送给会员,他们要求我包括以下代码:
I have a Woocommerce store and I like to send an order completion data to an affiliate and they ask me to include the following code:
<script>
lw("setCurrency", "numeric currency code, e.g. 978 for Euro");
lw("addItem", {
id: "ID (as given in the XML) of first product in order"
,price: "unit price of first product, without VAT e.g. 13,49"
,quantity: "quantity of first product"
,payout: "1"
});
lw("addItem", {
id: "ID (as given in the XML) of second product in order"
,price: "unit price of second product, without VAT e.g. 25,16"
,quantity: "quantity of second product"
,payout: "1"
});
// more items
lw("setCoupon", "0");
lw("thankyou", {
orderid: "unique order ID"
,status: "pending"
});
</script>
<noscript>
<img
src="//go.linkwi.se/delivery/acl.php?program=program_ID&decimal
=,_or_.&itemid[1]=ID_of_first_product&itemprice[1]=unit_pri
ce_of_first_product&itemquantity[1]=quantity_of_first_product&a
mp;itempayout[1]=1&itemid[2]=ID_of_second_product&itemprice
[2]=unit_price_of_second_product&itemquantity[2]=quantity_of_se
cond_product&itempayout[2]=1&coupon_price=0&status=pend
ing&orderid=unique_order_ID" style="width:0px;height:0px;"/>
</noscript>
在我的感谢页面"-结帐页面"中.
In my thank you page - Checkout Page.
我已了解到这与WooCommerce数据层有关,我已经搜索了许多小时,没有发现任何对我有帮助的东西.
I have read that this is related to the WooCommerce Data Layer, I have searched for many hours not found anything to help me.
谢谢.
添加其他信息
我使用WordPress的Header and Footer插件并输入以下代码:
I use the Header and Footer plug in of WordPress and put the following code:
<!-- LinkWise Script -->
<script async src="//go.linkwi.se/delivery/js/tl.js"></script>
<script>
window.lw=window.lw||function(){(lw.q=lw.q||[]).push(arguments)};lw
.l=+new Date;
lw("setProgram", "12686");
lw("setDecimal", ",");
</script>
<!-- End LinkWise Script -->
网站每页标题上的
推荐答案
这里是一种将其集成的方法;但是您必须在代码中添加一些设置:
Here is a way to integrate it; But you will have to add some settings to the code:
- 程序编号(您的程序联盟ID)
- 小数点分隔符(可以是逗号或点).
- 货币编号代码(采用ISO_4217格式).
您将不得不不再需要从页眉或页脚中删除其他相关代码 ...
代码分为2部分:
- 包含Linkwise关联脚本(和设置)的实用程序功能
- 将根据收到的订单(2个选择)运行Linkwise Affiliate脚本的挂钩函数:
第一个功能(您将在其中添加设置的地方):
// Utility function that contain Linkwise Affiliate script
function linkwise_affiliate_scripts( $order_id ){
## --- YOUR SETTINGS START BELOW --- ##
$program_id = '12686'; // <== Your program number
$decimal_sep = ','; // Decimal separator
$currency = '978'; // For "EUR" => See: https://en.wikipedia.org/wiki/ISO_4217
## --- END SETTINGS --- ##
$order = wc_get_order( $order_id );
$order_status = $order->get_status();
$items_string = array();
$count = 0;
?>
<script async src="//go.linkwi.se/delivery/js/tl.js"></script>
<script>
window.lw=window.lw||function(){(lw.q=lw.q||[]).push(arguments)};
lw .l=+new Date;
lw("setProgram", "<?php echo $program_id; ?>");
lw("setDecimal", "<?php echo $decimal_sep; ?>");
</script>
<script>
lw("setCurrency", "<?php echo $currency; ?>"); // Set your currency
<?php
foreach( $order->get_items() as $item ):
$count++;
$item_id = $item->get_id(); // The item ID
// Get an instance of the WC_Product object
$product = $item->get_product();
$product_id = $item->get_product_id(); // Product ID
$price_excl_vat = wc_get_price_excluding_tax( $product ); // Unit price excluding VAT
$item_qty = $item->get_quantity(); // Item quantity
$payout = '1'; // (???)
// The string for the <noscript> at the bottom
$items_string[] = "itemid[$count]=$item_id&itemprice[$count]=$price_excl_vat&itemquantity[$count]=$item_qty&a
mp;itempayout[$count]=$payout";
?>
lw("addItem", {
id: "<?php echo $item_id; // Or can be the product ID (may be) ?>"
,price: "<?php echo $price_excl_vat; ?>"
,quantity: "<?php echo $item_qty; ?>"
,payout: "<?php echo $payout; ?>"
});
<?php
endforeach;
// Set the array of items strings in a unique string
$items_string = implode( '&', $items_string );
?>
// Other items types
<?php
$coupon_discounts = $coupon_discounts_tax = 0;
foreach( $order->get_items('coupon') as $item_coupon ){
$coupon_discounts += $item_coupon->get_discount();
$coupon_discounts_tax += $item_coupon->get_discount_tax();
}
?>
lw("setCoupon", "<?php echo $coupon_discounts; ?>");
lw("thankyou", {
orderid: "<?php echo $order_id; ?>"
,status: "<?php echo $order_status; ?>"
});
</script>
<noscript>
<img
src="//go.linkwi.se/delivery/acl.php?program=<?php echo $program_id; ?>&decimal=<?php echo $decimal_sep; ?>&<?php echo $items_string; ?>&coupon_price=<?php echo $coupon_discounts; ?>&status=<?php echo $order_status; ?>&orderid=<?php echo $order_id; ?>" style="width:0px;height:0px;"/>
</noscript>
<?php echo 'test';
}
以及将运行实用程序功能的挂钩函数(有2种不同的可能性):
And the hooked function that will run the utility function (with 2 different possibilities):
A)使用woocommerce_thankyou
动作挂钩:
add_action( 'woocommerce_thankyou','wc_linkwise_affiliate_thanyou_integration', 20, 1 );
function wc_linkwise_affiliate_thanyou_integration( $order_id ){
if ( empty($order_id) || $order_id == 0 )
return; // Exit
linkwise_affiliate_scripts( $order_id ); // Run the Linkwise Affiliate
}
B)或使用WordPress wp_footer
操作钩子:
B) or Using WordPress wp_footer
action hook:
add_action( 'wp_footer', 'wc_linkwise_affiliate_order_received_integration' );
function wc_linkwise_affiliate_order_received_integration() {
if ( ! is_wc_endpoint_url( 'order-received' ) )
return; // Exit
global $wp;
$order_id = absint( $wp->query_vars['order-received'] );
if ( empty($order_id) || $order_id == 0 )
return; // Exit
linkwise_affiliate_scripts( $order_id ); // Run the Linkwise Affiliate
}
代码进入活动的子主题(或主题)的function.php文件中.
经过测试,可以正常工作.
Tested and works.
您可以在浏览器控制台中检入,在收到订单"页面中将看不到任何错误和正确的输出标志.
You can check in your browser console, you will see no errors and the correct output flags in Order received page.
这篇关于Woocommerce感谢页面中的Linkwise会员集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!