WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Help Me
    Member
    Posted 7 months 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]; ?>')">
    						</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!

  2. WPyogi
    Volunteer Moderator
    Posted 7 months ago #

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

    http://wordpress.org/support/plugin/advanced-custom-fields

  3. Help Me
    Member
    Posted 7 months 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
    Volunteer Moderator
    Posted 7 months 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.

Reply

You must log in to post.

About this Topic