Latest news

How To Change Add To Cart Button Text and Relink In Magento?

No comments

TASK: Change Add To Cart button text to “Find Out More”

Moreover, when the customers click on the button, it will be redirected to a different URL on the website.

 

SOLUTIONS:

  •  1st Method: Modifying your code as below and check in the file …template/catalog/product/view/addtocart.phtml

Change from:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>

To:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Find Out More'); ?>
<?php $externalURL = 'your different URL'; ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
        <?php endif; ?>
        <button type="button" title="<?php echo $this->__('Find Out More') ?>" class="button btn-cart" onclick="setLocation('<?php echo $externalURL ?>')">
			 <span>
				<span><?php echo $this->__('Find Out More') ?></span>
			 </span>
		 </button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>

 

  • 2nd Method: Implementing these following steps:

Create the attribute ‘find_out_more’ with yes or no and then create an attribute to get the link ‘get_link’ if choose yes for the first one.

Now, open the file addtocart.phtml like in the 1st method and use the following code:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Find Out More'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
        <?php endif; ?>
		
		<?php if($_product->getData('find_out_more')==1){?>
			<button type="button" title="<?php echo $this->_('') ?>" class="button btn-cart" onclick="<?php echo $_product->getData('get_link'); ?>"><span><span><?php echo $buttonTitle ?></span></span></button>
		<?php }else { ?>
			<button type="button" title="<?php echo $this->_('Add to Cart') ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $this->_('Add to Cart') ?></span></span></button>
		<?php } ?>
		
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>

We have shown you how to custom the Add to cart button in Magento. If you have any problems when following these instruction, please leave a comment and we’re glad to help!

See More:

[Ultimate Guide] Converting Your Site To Google Progressive Web Apps (Part 1)

[Ultimate Guide] Converting Your Site To Google Progressive Web Apps (Part 1)

How To Configure Tax Rules In Magento 2?

[Hot Release] Magento Progressive Web Apps – Free Download

How To Set Up Flat Rate Shipping In Magento 2?

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...
April LeeHow To Change Add To Cart Button Text and Relink In Magento?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *