1

I want to add "Buy on Amazon" button on my product page. I was successful in adding it with this code: <a href="<?php echo $this->getProduct()->getamazonurl(); ?>"><img src="/media/wysiwyg/buy_on_amazon.png"></a>

I created an attribute amazonurl & added it to the required attributes set. Now I can enter the link of my product in that field. Problem is I'm not selling all the products that are listed on my website, so I want this button to appear only if there is a value (URL) entered in attribute's field. How do I do it? Because currently it's appearing regardless of the value entered.

  • Hello @Mohit, Please check my answer. – Pawan Nov 26 '18 at 18:07
1

You need to modify:

app/design/frontend/{Package}/{theme}/template/catalog/product/view/addtocart.phtml

    <?php if($this->getProduct()->getamazonurl()){ ?>
        <a target="_blank" href="<?php echo $this->getProduct()->getamazonurl(); ?>"><img src="/media/wysiwyg/buy_on_amazon.png"></a>
    <?php } ?>

Hope above will help!

  • Thanks, @Pawan. Just wanted to add that my website already have "Buy Now" & "Add to Cart" button. This "Buy on Amazon" would be the third button & this will only appear if I add Amazon's URL. This shouldn't affect the default Buy Now & Add to Cart Buttons, they should appear regardless or along with Amazon's button. Would your code still work in this condition? – Mohit Singh Nov 26 '18 at 18:19
  • if you need "Buy on Amazon" along with add to cart, You can add my updated code. – Pawan Nov 26 '18 at 18:23
  • just add above code at the end of file – Pawan Nov 26 '18 at 18:24
  • Welcome @MohitSingh :) – Pawan Nov 27 '18 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.