Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Help Me on "Amazon Affiliates Links using Function.php to generate link also using ACF field"

$
0
0

Hi there,

Basically I am trying to get a function to work in a page theme file so that I can set a link on an image and some text to the products amazon page. I have create Books as a custom post type, and have developed a number of customer fields using Advanced Custom Fields.

One of these fields is n Amazon Affiliate Product Number.

This number is to be used as part of the link.

Currently my function in function.php looks like this:

function getAffiliateLink($productCode)

{

  global $VisitorCountry;

  if ( isset($VisitorCountry) ) {

    if ($VisitorCountry->GetCode() == 'GB') {

      return 'http://amazon.co.uk/gp/product/' . $productCode . '/?tag=indautlan-21';

    } else if ($VisitorCountry->GetCode() == 'CA') {

      return 'http://amazon.ca/gp/product/' . $productCode . '/?tag=indautlan00-20';

    } else {

      return 'http://amazon.com/gp/product/' . $productCode . '/?tag=indautlan-20';

    }

  }

}

One of my anchor tags currently looks like this:

<a href="<?php ?>" title="Get more details for <?php the_title(); ?>">
						<div id="book-cover" class="featured" style="background-image:url('<?php echo $image[0]; ?>')">
						</div>
					</a>

This is missing the href obviously as I am still trying to work out how to call the function, as well as place the Amazon Product Number in the $productCode variable in the function.

Also, I call the Amazon Product Number from Advanced Custom Fields using:

$asin = get_field(amazon_product_code);

Any help anyone could give me on this would be highly welscomed... I also have another post open on another issue but regarding the same site, that can be found here:

Hope to hear back from someone soon, any help on this would be very very appreciated, sure I'm just missing something simple!


Viewing all articles
Browse latest Browse all 8245

Trending Articles