• Resolved blauweogen

    (@blauweogen)


    I would like to automatically add the affiliate id to the links of posts authors create. (?aff=1) for example.
    When a user creates a post (custom post type) I want their affiliate ID to be appended to the end of the slug. (https://example.com/listing/some-listing/?aff=1) So that the user (author) gets any sales that result from that post.

    Does anyone know how to add maybe a permalink tag or insert it into the slug or url?
    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author iova.mihai

    (@iovamihai)

    Hey @blauweogen,

    Thank you for reaching out! Technically speaking, this could be achieved using the “post_type_link” filter (you can find more details here: https://developer.www.ads-software.com/reference/hooks/post_type_link/).

    What this does, is modify the post’s URL when the get_post_permalink() function is called.

    This is sort of what you’d be looking for if I understood the situation correctly. However, it’s not something that I wouldn’t recommend, as it would turn all instances of the post’s link into a referral link.

    For any visitor clicking these links on your website, the referral cookie will be set, which in turn will result in a commission for the affiliate (author) if the visitor makes a sale. You could end up with quite a lot of commissions.

    If you’d like to have this scenario, please let me know. I can write a small piece of code for you to help with this.

    Thank you and best wishes,
    Mihai

    Thread Starter blauweogen

    (@blauweogen)

    Hi, iova.mihai (@iovamihai)
    Thank you so much for your reply. It is more than I hoped for! That is the scenario I want. I want the author to make commissions on what they post, and hopefully, it will encourage them to share the post more. And easier too. I would be very grateful for any bit of code you could give me.

    Thank you!

    • This reply was modified 2 years, 7 months ago by blauweogen.
    Plugin Author iova.mihai

    (@iovamihai)

    Hey @blauweogen,

    In this case, I recommend adding this following block of code to your site:

    function slicewp_custom_post_type_link( $post_link, $post ) {
    	
    	// Make sure SliceWP is active.
    	if ( ! function_exists( 'slicewp' ) )
    		return $post_link;
    	
    	// Don't modify links in the admin area.
    	if ( is_admin() )
    		return $post_link;
    	
    	// Modify only links for the "custom_post_type" post type.
    	if ( $post->post_type != 'custom_post_type' )
    		return $post_link;
    	
    	// Get the affiliate (post author) for this post.
    	$affiliate = slicewp_get_affiliate_by_user_id( $post->post_author );
    	
    	// Make sure the affiliate exists.
    	if ( is_null( $affiliate ) )
    		return $post_link;
    	
    	// Make sure the affiliate is active.
    	if ( $affiliate->get( 'status' ) != 'active' )
    		return $post_link;
    	
    	// Transform the post link into an affiliate referral link.
    	$post_link = slicewp_get_affiliate_url( $affiliate->get( 'id' ), $post_link );
    	
    	return $post_link;
    	
    }
    add_filter( 'post_type_link', 'slicewp_custom_post_type_link', 10, 2 );

    The only thing you’d need to do is change the “custom_post_type” string to your custom post type’s actual key/slug. I’ve commented the code for each step so it’s easier to understand. I hope it makes sense.

    If you’re not sure how to add this code to your website, you can use the Code Snippets plugin (https://www.ads-software.com/plugins/code-snippets/).

    Please try it out and let me know how it goes.

    Thank you and best wishes,
    Mihai

    Thread Starter blauweogen

    (@blauweogen)

    Beautiful! Exactly what I needed. Still testing, but works perfectly so far. I am planning to use SliceWP Pro on a few sites in the near future.
    Thanks @iovamihai

    Plugin Author iova.mihai

    (@iovamihai)

    Hey @blauweogen,

    No worries whatsoever! Happy to hear it’s working as you need it to.

    If you have any additional questions, please make sure to open a new support topic and I’ll try to get back to you as quickly as I can.

    Thank you and best wishes,
    Mihai

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add affiliate ID tag to Permalinks’ is closed to new replies.