Streaming live at 10am (PST)

Append a function to outbound links


#1

I'm trying to set up my webflow-based site to pass affiliate link information over to a wordpress-based site that has AffiliateWP installed on it. This way, an affiliate could send someone to one of our resources, but still get credit for a purchase if the referred visitor leaves the webflow site and purchases on our wordpress site with AffiliateWP installed.

Apparently, this is how I'm supposed to do it. But I really don't know what this means. Can anyone tell me how (/if it's possible) to "append this function to my purchase links", as described below?

Here's my read-only link: https://preview.webflow.com/preview/salesographer-course?preview=407f7f389d5fada073d8d10d5b25745f

<?php
    /**
     * Non WordPress version of https://gist.github.com/sumobi/35791ee325a4715c6fd8
     * 
     * Useful for when your landing page is on a separate domain where AffiliateWP is not installed.
     * Retrieves the referral variable and value from the landing page's URL and passes it to the purchase button/s on the same page.
     * When a customer clicks the purchase button/s, they will be taken to your e-commerce site where the proper affiliate will be tracked/awarded commission.
     * 
     * Append the function to your purchase links like so:
     * <a href="http://yoursalessite.com/<?php if ( function_exists('affwp_custom_append_affiliate_id') ) { echo affwp_custom_append_affiliate_id(); } ?>">Buy now</a>
     *
     * Example:
     * 
     * Customer is sent to your landing page with a URL of http://yourlandingpage.com/?ref=123
     * 
     * This will result in the outbound link having a URL of:
     * http://yourshop.com/?ref=123
     */
    function affwp_custom_append_affiliate_id() {
     
    	// Set the referral variable. It should match the same one you are using in AffiliateWP
    	$referral_var = 'ref';
     
    	// get the value of the referral variable from the URL
    	$affiliate_id = isset( $_GET[$referral_var] ) ? $_GET[$referral_var] : '';
     
    	// if the referral variable exists, return a formatted query string for use in our links Eg. /?ref=123
    	if ( $affiliate_id ) {
    		return '/?' . $referral_var . '=' . $affiliate_id;
    	}
    }

#2

You cannot run PHP code in Webflow sites. Is there a JavaScript version of this?


#3

Doesn't appear to be. I'll reach back out to AffiliateWP to find out. Thanks for chiming in, samliew!


#4