Display affiliate links to affiliates

Is there a way to first display code that will show the current affiliate link of the affiliate who is logged in, so we can present promotional ideas and all they need to do is copy the link displayed on the page?

Second, is there a way to display the corresponding affiliate's link on their Pro-Sites dashboard, even in easy blogging dashboard or in regular dashboard?

Kindly,

Paul

  • Adam Czajczyk

    Hey Paul,

    I hope you're well today and thank you for using our Affiliates plugin!

    There are shortcodes for Affiliates plugin that you may use for this. To display an affiliate link simply put this anywhere on your page (it may be a post, a page or any type of custom content):

    [affiliatelogincheck]
    [affiliateuserdetails]
    [affiliatestatstable]

    To put this on ProSites checkout page for example, simply go to your dashboard's

    "Network Admin" -> "Pro Sites" -> "Settings" page,

    scroll down until you see "Checkout Page" option and click on "Edit Checkout Page" link. It will redirect you to a page editor where you can insert those aforementioned shortcodes.

    For more handy shortcodes, please take a look a this instruction (just scroll down to about middle of the page - "Shortcodes" section):

    https://premium.wpmudev.org/project/wordpress-mu-affiliate/

    I hope that helps!

    Cheers,
    Adam

  • Paul

    Hi adam, Thank you very much for your reply.
    I will use these shortcodes you shown. But is there a way or any way to display the affiliates link on it's own. So we can direct attention to the link alone?

    Example. On every member page we want to have the affiliate's link showing in the top right hand of each page. So they can copy and use it at any time during our training sessions.

    Is there a way to do this or a code I can use quickly to just call this information up in any form?

    Most Kindly,

    Paul

  • Adam Czajczyk

    Hey Paul,

    I hope you're well today!

    Those shortcodes are enabled by design, however I've got a piece of custom code for you here. Please place it in your theme's functions.php file:

    function wpmu_affiliate_link_shortcode() {
    		$user = wp_get_current_user();
    		$user_ID = $user->ID;
    
    		if(empty($user_ID)) {
    			return '';
    		}
    
    		if(function_exists('is_multisite') && is_multisite() && function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('affiliate/affiliate.php')) {
    			$site = aff_get_option('site_name');
    			// switch to use new option
    			$siteurl = get_blog_option(1,'home');
    			$affiliatelinkurl = aff_get_option( 'affiliatelinkurl', $siteurl );
    		} else {
    			$site = aff_get_option('blogname');
    			// switch to use new option
    			$siteurl = aff_get_option('home');
    			$affiliatelinkurl = aff_get_option( 'affiliatelinkurl', $siteurl );
    		}
    		if(get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
    				$reference = get_user_meta($user_ID, 'affiliate_reference', true);
    		}
    		$affiliatelinkurl .= '?ref=' . $reference;
    		return $affiliatelinkurl;
    }

    This will display the affiliate link anywhere on the page as a simple string.

    I hope that helps!

    Adam

  • Adam Czajczyk

    Hey Paul,

    I hope you're well!

    Oooops! I forgot that part :slight_smile: I apologize!

    Actually, I've also omitted one more important piece. Having said that, first please add this line below the function from my previous post:

    add_shortcode('affiliateuserlink','wpmu_affiliate_link_shortcode');

    Now, you may display the affiliate link two ways:

    1. place this shortcode anywhere in the post/page:

    [affiliateuserlink]

    2. call it in your theme's template file like this:

    <?php
    echo do_shortcode('[affiliateuserlink]');
    ?>

    I hope this time I didn't forget anything :slight_smile:

    Cheers,
    Adam

  • Adam Czajczyk

    Hey Paul,

    I hope you're well today!

    I should have been more specific on this one :slight_smile:
    The "add_shortcode('affiliateuserlink','wpmu_affiliate_link_shortcode');" line shoud be placed underneath the function, right under the closing } bracket. Here's the updated code for you:

    function wpmu_affiliate_link_shortcode() {
    		$user = wp_get_current_user();
    		$user_ID = $user->ID;
    
    		if(empty($user_ID)) {
    			return '';
    		}
    
    		if(function_exists('is_multisite') && is_multisite() && function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('affiliate/affiliate.php')) {
    			$site = aff_get_option('site_name');
    			// switch to use new option
    			$siteurl = get_blog_option(1,'home');
    			$affiliatelinkurl = aff_get_option( 'affiliatelinkurl', $siteurl );
    		} else {
    			$site = aff_get_option('blogname');
    			// switch to use new option
    			$siteurl = aff_get_option('home');
    			$affiliatelinkurl = aff_get_option( 'affiliatelinkurl', $siteurl );
    		}
    		if(get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
    				$reference = get_user_meta($user_ID, 'affiliate_reference', true);
    		}
    		$affiliatelinkurl .= '?ref=' . $reference;
    		return $affiliatelinkurl;
    }
    add_shortcode('affiliateuserlink','wpmu_affiliate_link_shortcode');

    I've tested it once again and it seems to work fine. Let me know please if it works for you!

    Cheers,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.