Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EricBusch/9e8514c57c1b8aa0d9d156b6e418179b to your computer and use it in GitHub Desktop.
Save EricBusch/9e8514c57c1b8aa0d9d156b6e418179b to your computer and use it in GitHub Desktop.
Use this code to replace the "@@@" placeholder in the "url" field with your affiliate network affiliate ID. [datafeedr]
<?php
/**
* Map each affiliate network ID to your affiliate ID for that network.
*
* In this example, Commission Junction's network ID is 3 and my Commission
* Junction affiliate ID is '321321321'.
*/
$affiliate_ids = array(
3 => '321321321', // Commission Junction Affiliate ID.
6 => '161493', // ShareASale Affiliate ID.
48 => 'VjUdjSOl*AJ', // Linkshare (Rakuten) Affiliate ID.
);
// Get the Affiliate Network ID from the $product array.
$network_id = $product['source_id'];
// Get the product's affiliate link URL from the $product array.
$product_url = $product['url'];
// Get the proper affiliate ID for this product's affiliate network.
$affiliate_id = $affiliate_ids[ $network_id ];
// Replace the "@@@" placeholder with your affiliate ID.
$affiliate_link = str_replace( '@@@', $affiliate_id, $product_url );
// Display the affiliate link.
echo '<a href="' . $affiliate_link . '">Buy Now</a>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment