cancel
Showing results for 
Search instead for 
Did you mean: 

Changing 'Add to cart' button text and relink

Changing 'Add to cart' button text and relink

Hi,

 

Ho do I change the 'add to cart' button text?.... need to change it to 'Find Out More'. 

 

Also, once they click on the button to be redirected to a different URL on the website. 

 

I need this function to be available just for some products. 

 

Thanks 

10 REPLIES

Re: Changing 'Add to cart' button text

@soundtech12a

 

In order to change label of Add to cart button then easily manage by Translate Inline (System >> Configuration >> Developer >> Translate Inline) but in your case you also want to change action of Add to cart button (redirect to another site) for that you need to do little code. Follow below steps.

1. Create new attribute for redirect url (Catalog >> Attributes >> Manage Attributes)

2. Assign your Attribute Sets to your created attribute. (Catalog >> Attributes >> Manage Attribute Sets)

3. Edit product in which you want to redirect on another site and find that created attribute and paste your external URL.

4 Now put condition into your respected (list.phtml, view.phtml) file Or rewrite class where add to cart URL get.

 

Hope it helps you Smiley Happy

-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Changing 'Add to cart' button text

Hey,

Thank you for your help.

 

I managed to change the text for the 'add to cart' button but the rest is a blur. I forgot to mention I started using Magento two weeks ago and my coding skills are almost existent. Smiley Sad

 

Can you please re-explain the steps in greater detail?

 

Much appreciated,
Daniel

Re: Changing 'Add to cart' button text

 Ok, after a bit of searching around I have the following setup but still needs some tweaking:

 

…. I have one attribute ‘find out more’ with yes or no and then an attribute for getting the link ‘get_link’ if I choose yes for the first one.

My code I guess should be the if- else type. If the ‘find out more’ attribute is YES link my add to cart button with the URL found under the get_link attribute.

 

if (condition) {
    show this button and link it to the ‘get_link’
} else {
    use normal  add to cart button
}

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

<?php if($_product->getData('find_out_more')==1){?>

 

<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="location.href='http://www.google.com'"><span><span><?php echo $buttonTitle ?></span></span></button>

} else {

                     

<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>

 <?php } ?>

 

the above code is under: product/view/addtocart.phtml

 

They break a bit the design but they seem to work, although onclick instead of linking to a link (location.href='http://www.google.com'">), I need it to open the link found under ‘get_link’ attribute. 

 

 

Help! Smiley Happy

Re: Changing 'Add to cart' button text

@soundtech12a

 

Okay so you're using two attributes first to check and second for the link. Actually there are some error in your code, try to code like below and check.

 

<?php $externalURL = 'http://www.google.com';?>

 <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $externalURL ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

Basically, in "$externalURL" get your 'get_link' attribute value.

 

Good luck Smiley Happy

 

-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Changing 'Add to cart' button text

Hey,

Thanks for the help. Is getting closer Smiley Happy

 

I changed the google url with the 'get_link' attribute but it does not take the url from the attribute. It ads get_link after the website url. Eg: www.example.com/get_link

 

I have the following code that takes the url form the 'get_link' attribute:  <?php echo $_product->getData('get_link'); ?>

 

How do I incorporate it in your code, so it replaces the google link?

 

<?php $externalURL = 'http://www.google.com';?>

 Thanks

Re: Changing 'Add to cart' button text

@soundtech12a

 

Try below

$attribute_value = $product->getResource()->getAttribute("get_link")->getFrontend()->getValue($_product);
-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Changing 'Add to cart' button text

Do you have flat catalog enabled? If so, you will need to make sure that the attribute is configured to be "Visible on Product View Page on Front-end" and/or "Used in Product Listing", depending on where you need it. You can chance this in Catalog > Attributes > Manage Attributes, then find the "get_link" attribute.

 

After you change this, make sure you re-index, that should make the value show up.

Problem solved? Click Accept as Solution!
www.iweb.co.uk | Magento Small Business Partner

Re: Changing 'Add to cart' button text

Hey,

Thank you for your help. After a bit of playing around with your suggestions I managed to get it working as intended. I will describe all the steps underneath is anyone else might need the same functionality.

 

So, if you need to replace the ‘Add To Cart’ button on a product basis, and would like the new button to have a different name (eg. Find out More) and link to a custom URL, please follow the following steps:

 

  1. Create two attributes:
  • Create a YES/No attribute to check whether you would like to change the button or not. (Catalog >> Attributes >> Manage     Attributes>>Add new attribute). In the ‘Catalog Input Type for Store Owner’ choose YES/NO. I named this attribute find_out_more. You can name it whatever you like but you need to change it in the code underneath.
  • Create a text field attribute to input your custom URL in. (Catalog >> Attributes >> Manage Attributes>>Add new attribute).In the ‘Catalog Input Type for Store Owner’ choose Text Field

Now add these two attributes in your attribute set relating to the products you want to have this functionality for.

(Catalog >> Attributes >> Manage Attributes Sets>>select you product set and drag them across)

 

Ok, to quickly summarize. The first attribute checks whether you like to replace the button, the second one is to use the custom URL for the new button. (Example: on button click, take me to google.com).

 

The code. Update in both. The addtocart.phtml is for the product page the list.phtm is for the list page. 

 

app/design/frontend/rwd/default/template/catalog/product/view/addtocart.phtml

app/design/frontend/rwd/default/template/catalog/product/list.phtml

 

The first two lines are for referencing the right name. Add the bottom line of code (buttonTitle2), the first line of code should already be there. Magento is using that as default to name the add to cart button. 

 

 

<?php $buttonTitle = Mage::helper('core')->quoteEscape($this->__('Add To Cart')); ?>
<?php $buttonTitle2 = Mage::helper('core')->quoteEscape($this->__('Find Out More')); ?>

 

The two blocks of code underneath are for my custom ‘FIND OUT MORE’ button and for the normal ‘ADD TO CART’ button. Basically they will be used based on what you choose in the YES/NO attribute. You can see at the beginning of the code. If ‘find out more’ attribute ==1 (YES) use this button. The other one is the reverse. If ==0 then use normal add to cart button. There is already a block of code for the add to cart button, you need to replace that with both of these. 

 

 

<?php if($_product->getData('find_out_more')==1){?>
<div class="add-to-cart-buttons">
<button type="button" title="<?php echo $buttonTitle2 ?>" class="button btn-cart" onclick="setLocation('<?php echo $_product->getData('get_link'); ?>')"><span><span><?php echo $buttonTitle2 ?></span></span></button>
<?php } ?>


   
<?php if($_product->getData('find_out_more')==0){?>
<div class="add-to-cart-buttons">
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<?php } ?>

 This is what worked for me but I'm sure if far from perfect. If you have sugetions and updates please let me know. 

Re: Changing 'Add to cart' button text

Thank you. it help me a lot to find out right file.