Forked from EricBusch/replace-placeholder-with-affiliate-id-in-product-url.php
Created
April 5, 2017 13:49
-
-
Save EricBusch/504df8bda3427ca420fb6c70e7f98df1 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]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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