Replace affiliate link with a Skimlinks link

While Datafeedr does not officially support Skimlinks, if you want to replace your affiliate links with a link to Skimlinks, here's the code to do so.

Warning

There are limitations to this method. Not all products contain the necessary data to redirect to Skimlinks. If the necessary data is not available, the affiliate network affiliate link will be returned instead. Therefore it's a good idea to enter your affiliate ID for all networks just in case.

This works best with most ( but not all) products from the following affiliate networks:

2Performant, ADCELL, Admitad, AdRecord, Adtraction, AWIN, Belboon, BettyMills, ClixGalore, Commission Junction, Digital Advisor, Effiliation, Impact, LinkConnector, Rakuten, Optimise, Partnerize, Partner-ads, PepperJam, Profitshare, The Affiliate Gateway, Tradedoubler, TradeTracker & Webgains.

Pro Tip

If you are using the Datafeedr Product Sets plugin and you only want to import products into your site which work with Skimlinks, then you should use the "Has Direct URL" filter and set the filter value to "yes".

Use "Has Direct URL" filter to only return Skimlinks-compatible products.

Let's begin!

1

Create a custom plugin

If you haven't done so already, create a custom plugin .

2

Add custom code

Add the following custom code to your custom plugin:

/**
 * Replace affiliate links with links to Skimlinks.
 *
 * There are limitations to this method. Not all products contain the necessary data
 * to redirect to Skimlinks. If the necessary data is not available, the affiliate network
 * affiliate link will be returned instead. Therefore, it's a good idea to enter your
 * affiliate ID for all networks just in case here WordPress Admin Area >Datafeedr API > Networks
 *
 * This works best with most (but not all) products from the following affiliate networks:
 *
 * 2Performant, ADCELL, Admitad, AdRecord, Adtraction, AWIN, Belboon, BettyMills,
 * ClixGalore, Commission Junction, Digital Advisor, Effiliation, Impact, LinkConnector,
 * Rakuten, Optimise, Partnerize, Partner-ads, PepperJam, Profitshare,
 * The Affiliate Gateway, TradeDoubler, TradeTracker & Webgains.
 *
 * To use this code you must add your Skimlinks ID at the top of the function. Replace 12345X6789123 with your
 * unique Skimlinks ID.
 *
 * @param string $url The current affiliate URL.
 * @param array $product An array of the current Datafeedr product's information.
 * @param string $affiliate_id Affiliate ID for current product.
 *
 * @return string URL.
 *
 */
add_filter( 'dfrapi_before_affiliate_id_insertion', function ( $url, $product, $affiliate_id ) {

	/**
	 * REQUIRED
	 *
	 * Add your Skimlinks unique ID here.
	 * Learn how to find this here @https://accounts.skimlinks.com/sites
	 * Replace 12345X6789123 with your unique Skimlinks ID.
	 */
	$skimlink_id = '12345X6789123';

	/**
	 * OPTIONAL
	 *
	 * If you only want to use Skimlinks for specific merchants, set
	 * this variable to true.
	 */
	$limit_to_specific_merchants = false;

	/**
	 * OPTIONAL
	 *
	 * If you only want to use Skimlinks for specific merchants, add those
	 * merchants' IDs to the example array below.
	 *
	 * You can find merchant IDs in the MID column on this
	 * page: https://www.datafeedr.me/networks
	 */
	$specific_merchants = [
		53492, // Macy's
		63122, // Bloomingdale's
		54419, // Target
	];

	// +++++++ Do not edit below this line +++++++

	if ( $limit_to_specific_merchants && ! in_array( absint( $product['merchant_id'] ?? 0 ), $specific_merchants, true ) ) {
		return $url;
	}

	$skimlink_url = 'http://go.redirectingat.com/';
	$skimlink_xs  = 1;
	$key          = 'direct_url';

	if ( ! isset( $product[ $key ] ) ) {
		return $url;
	}

	$direct_url = $product[ $key ];

	if ( substr( $direct_url, 0, 4 ) !== 'http' ) {
		$direct_url = 'http%3A%2F%2F' . $direct_url;
	}

	return add_query_arg( [
		'xs'  => $skimlink_xs,
		'id'  => $skimlink_id,
		'url' => $direct_url,
	], $skimlink_url );

}, 20, 3 );
3

Add your Skimlinks ID

Replace 12345X6789123 with your Skimlinks site ID.

4

Save

Save your custom plugin file.

Now any product which has the required data for being converted into a Skimlinks link will be converted.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us