[resolved] Amazon Affiliates Links using Function.php to generate link also using ACF field (4 posts)

  1. adamraybicknell
    Posted 2 years ago #

    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]; ?>')">

    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!

  2. WPyogi
    Forum Moderator
    Posted 2 years ago #

    Please see the post at the top of the sub-forum for this plugin:


  3. adamraybicknell
    Posted 2 years ago #

    The question isn't exactly about ACF, that's not the problem on this one, it's working fine.

    The problem with this one is me not being able to work out how to get the function to create links within my page template

  4. WPyogi
    Forum Moderator
    Posted 2 years ago #

    In that case, it should really be posted in the "Hacks" sub-forum - here: http://wordpress.org/support/forum/hacks

    It won't likely be seen here.

    I will move this thread there.

Topic Closed

This topic has been closed to new replies.

About this Topic