Skip Navigation

[Resolved] Create Custom Affiliate Link

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display conditional content using taxonomy term

Solution:
You can use [wpv-conditional] shortcode in order to display conditional content based on taxonomy term.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/create-custom-affiliate-link/#post-900897

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by chrisB-30 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#895118

Hello,

I need to create a dynamic affiliate link that is created by looking at 2 different variables in the Post type called "Brides":

Agency - which is a taxonomy
ID# - which is a field

Each of the "Agencies" have a different linking structure for their affiliate links. So, I first need to look at which "Agency" the entry is associated with then, depending on the outcome, I need to create a custom url by inserting the "ID#" of the entry into the url of the affiliate link.

It is even more complicated because most of the URLs need to have the ID# dynamically inserted into the middle of the URL, like this:

hidden link

I am currently using Joomla/SobiPro to do this.

Here is a snippet of the code that Sobipro uses to generate the dynamic urls to give you a better idea of what I'm talking about:
--------------------------------------------
<xsl:choose>
<xsl:when test="entry/fields/field_agencies/data = 'Amolatina' ">
<xsl:attribute name="href">
<xsl:text>hidden link;

<xsl:value-of select="entry/fields/field_id/data"/>

<xsl:text>%26afid%3D20103%26subafid%3D{affiliate_id}%26transaction-id%3D{transaction_id}%26offer-id%3D{offer_id}</xsl:text>
</xsl:attribute>
</xsl:when>

<xsl:when test="entry/fields/field_agencies/data = 'Anastasia' ">
<xsl:attribute name="href">
<xsl:text>hidden link;

<xsl:value-of select="entry/fields/field_id/data"/>

<xsl:text>%26afid%3D20068%26subafid%3D{affiliate_id}%26transaction-id%3D{transaction_id}%26offer-id%3D{offer_id}%26RMC%3D{aff_sub}%26utm_source%3DHasOffers%26utm_medium%3DCPA%26utm_campaign%3DFirstOrder</xsl:text>
</xsl:attribute>
</xsl:when>

-------------------------------------------

I would like to output the finished URL as a shortcode so I can use it to add the link to an image in my main content template.

I have been trying to figure this out for 2 days now - could you take a look and see if you can lead me in the right direct. If you can just give me a basic overview of how you would achieve this I could probably figure out the particulars by myself.

Thanks!

internationallovescout.info/wp-admin
ChrisB
test99

#895142

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - We are as a supporters we need to work within our defined boundary and we are not allowed to debug the third party APIs or plugins. I know this is not the answer that you would like to hear but I can to do much here.

I see there is no Toolset involved here and actually the thing is that this is pure custom programming which is beyond the scope of our support policy. I hope I make things clear and thank you for understanding the defined limits.

Its clear that you need to debug the API and write your own shortcode to get dynamic URL as per your requirement. If you need custom programming for your project, please feel free to contact our certified parthers:
=> https://toolset.com/contractors/

#895872

I was not asking anyone to debug 3rd party software - I included a snippet of Sobipro to illustrate what I had done on the joomla version of the site. I am moving the site to WordPress Toolset - whichis in fact the plugin which this support forum is for!!!

#895924

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I reopen your ticket to give you support and I check with my one of the senior college and he cleared the way so I'm happy to guide you with your query. Sorry for the inconvenience.

You shared the following link:

 <em><u>hidden link</u></em>

As I understand, you just want to replace the [VARIABLEID#] with the original taxonomy term ID - correct?

Can you show me one example what you have done so far for now and where exactly you want to build this link. The XML structure you shared is however not understandable and I do not know whats the role of that and what it gives as end result.

#900870

Hello,

The XML was just given as an example of the way it was handled on Joomla. Let's just forget about that to avoid confusion.

hidden link

I would like to replace the [variableID#] with the ID# - the ID number is a custom field for the Post Type "Brides"

The Taxonomy that I need to query is called "Agencies"

So first I would like to create a url like this
hidden link

Then I would like to query the taxonomy "Agencies" and output something like this:

if Agency = "amolatina" display this
hidden link field='id'][/types]2ndparturl"

if Agency = "anastasiadate" display this
hidden link field='id'][/types]2ndparturl"

if Agency = "aaforeignaffair" display this
hidden link field='id'][/types]/2ndparturl"

Please not 2 things:
1. The url construction is a different format for all the agencies.
2. The [ID#] field has to be inserted into the middle of the url.

So, now that the custom url is created I need to add the link to an image in my main content template.
You can see an example of the image I need to add the link to at this url:
hidden link

The site is locked so you will need to log in to see that page:
hidden link
ChrisB
test99

I have tried several things but have not come up with anythinng that works. If you could just give me a general idea of how to start I could probably work out the details myself. Is it possible to do this with Views or do I need to use the API?

Thanks!

#900894

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

hidden link
I would like to replace the [variableID#] with the ID# - the ID number is a custom field for the Post Type "Brides"
==> So basically you can use types shortcode to retrieve the ID# field value.

For example:

<em><u>hidden link</u></em> field='id' output='raw'][/types]moreurlvariableshere

Now, do you want to build such URL for each and every "Brides" - If yes: you should create a view and adjust your URL accordingly.

Now regarding this:
if Agency = "amolatina" display this
hidden link field='id'][/types]2ndparturl"

if Agency = "anastasiadate" display this
hidden link field='id'][/types]2ndparturl"

if Agency = "aaforeignaffair" display this
hidden link field='id'][/types]/2ndparturl"
=======>
You can use [wpv-conditional] shortcode to display conditional content.

For example:

[wpv-conditional if="( has_term('amolatina', 'agency', null) eq '1' )" ]
 <a hfef="<em><u>hidden link</u></em> field='id' output='raw'][/types]2ndparturl"</a>
 [/wpv-conditional]

[wpv-conditional if="( has_term('anastasiadate', 'agency', null) eq '1' )" ]
 <a hfef="<em><u>hidden link</u></em> field='id' output='raw'][/types]2ndparturl"</a>
 [/wpv-conditional]

[wpv-conditional if="( has_term('aaforeignaffair', 'agency', null) eq '1' )" ]
 <a hfef="<em><u>hidden link</u></em> field='id' output='raw'][/types]2ndparturl"</a>
 [/wpv-conditional]

Please check following Doc:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific

#900897

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

For example - I've added following code to your beaver builder text module that displays the image:

[wpv-conditional if="( has_term('amolatina', 'agency', null) eq '1' )" ]
<a href="<em><u>hidden link</u></em> field='id' output='raw'][/types]2ndparturl">
[types field='logo' alt='%%ALT%%' title='%%TITLE%%' width='300' align='center' resize='proportional'][/types]
</a>
[/wpv-conditional]

Now if you can visit the following page and hover mouse cursor you can see the link is added to image and it also displays the ID# field value in URL.
=> hidden link

You need to add [wpv-conditional] shortcode for every taxonomy term just like above. With above code we are checking for taxonomy term "amolatina" as you can see.

Could you please confirm.

#900920

Awesome - I didn't even think about doing the conditional in the template.
THANKS!

#900924

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

May I kindly ask you to remove the comment you've added to my profile 🙂

#901352

Yes I would be happy to - can you tell me how I can do that?