Linkwise Affiliate integration in Woocommerce thankyou page

Linkwise Affiliate integration in Woocommerce thankyou page



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&amp;decimal
=,_or_.&amp;itemid[1]=ID_of_first_product&amp;itemprice[1]=unit_pri
ce_of_first_product&amp;itemquantity[1]=quantity_of_first_product&a
mp;itempayout[1]=1&amp;itemid[2]=ID_of_second_product&amp;itemprice
[2]=unit_price_of_second_product&amp;itemquantity[2]=quantity_of_se
cond_product&amp;itempayout[2]=1&amp;coupon_price=0&amp;status=pend
ing&amp;orderid=unique_order_ID" style="width:0px;height:0px;"/>
</noscript>



In my thank you page - Checkout Page.



I have read that this is related to the WooCommerce Data Layer, I have searched for many hours not found anything to help me.



Thank you in advance.



Adding additional info



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;lw
.l=+new Date;
lw("setProgram", "12686");
lw("setDecimal", ",");
</script>

<!-- End LinkWise Script -->



on every page of the website on header




1 Answer
1



Here is a way to integrate it; But you will have to add some settings to the code:



You will have to remove other related code from header or footer as not needed anymore…



The code is divided in 2 parts:



The first function (Where you will add your settings):


// 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



And the hooked function that will run the utility function (with 2 different possibilities):



A) Using woocommerce_thankyou action hook:


woocommerce_thankyou


add_action( 'woocommerce_thankyou','wc_linkwise_affiliate_thanyou_integration', 20, 1 );
function wc_linkwise_affiliate_thanyou_integration( $order_id )



B) or Using WordPress wp_footer action hook:


wp_footer


add_filter( 'wp_footer', 'wc_linkwise_affiliate_order_received_integration' );
function wc_linkwise_affiliate_order_received_integration() $order_id == 0 )
return; // Exit

linkwise_affiliate_scripts( $order_id ); // Run the Linkwise Affiliate



Code goes in function.php file of your active child theme (or theme).



Tested and works.



You can check in your browser console, you will see no errors and the correct output flags in Order received page.






Thank you very much for your answer i want to apologize for not including the following code: <script async src="//go.linkwi.se/delivery/js/tl.js"></script> <script> window.lw=window.lw||function()(lw.q=lw.q;lw .l=+new Date; lw("setProgram", "program ID as given by Linkwise"); lw("setDecimal", "decimal separator i.e. , or ."); </script> they did provide for the header of every page since it was easy to implement. Maybe this is one for the missing lw(). What are my next step? Do i need to include the master Script? How and where since i am not experienced.

– Tasos Karatzoglou
Feb 23 '18 at 19:54







I am just thinking that the missing JavaScript (js) file must be int this source src="//go.linkwi.se/delivery/js/tl.js which load on every page on the header. I just added the suggested code in the end of my child theme php file and the thank you page does not load anymore.

– Tasos Karatzoglou
Feb 23 '18 at 20:11






Edited code added

– Tasos Karatzoglou
Feb 23 '18 at 20:25






Great Solution my friend. Thank you for your valuable time.

– Tasos Karatzoglou
Feb 23 '18 at 22:09






@TasosKaratzoglou Just for info: I have maid an update with 2 alternatives (2 different working hooks)… You can keep your version as it works…

– LoicTheAztec
Feb 24 '18 at 9:26



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)