Auto generate referral links | WordPress.org

[ad_1]

Hey @bacco4249 and @obmerlo,

Thank you for reaching out! This currently cannot be done out of the box, however, it can be done via a custom shortcode.

Firstly, please add the following code snippet to your website:

function slicewp_custom_shortcode_affiliate_url_input_field() {

    if ( is_admin() ) {
        return;
    }

    if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
        return;
    }
	
	$output="";

    if ( is_user_logged_in() && slicewp_is_affiliate_active( slicewp_get_current_affiliate_id() ) ) {
		
		$referal_link = slicewp_get_affiliate_url( slicewp_get_current_affiliate_id(), get_permalink() );
		$output="<input type="text" style="display: block; width: 100%; margin-top: 10px;" value="" . esc_url( $referal_link ) . '"/>';
		
	}

    return $output;

}
add_shortcode( 'slicewp_custom_shortcode_affiliate_url_input_field', 'slicewp_custom_shortcode_affiliate_url_input_field' );

Please copy the code and add it to your website. If you’re not sure how to add code snippets to your site, you can use the Code Snippets plugin (https://projectdmc.org/plugins/code-snippets/).

Then, add the [slicewp_custom_shortcode_affiliate_url_input_field] shortcode to your website, where you want to output the field with the affiliate’s referral link.

If a non-affiliate user is viewing the page, nothing will be outputted.

Thank you and best wishes,

Mihai

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer