Add XX to Cart for Free Shipping – Magento

Create Apple's style of Add XX to your order and get Free Shipping

In Magento you can do the same in the checkout page. With the snippet below you can retrieve the free delivery amount value from the admin, convert it to the actual currency and do the math.

It's important to convert the currency so the user can switch between EUR, USD or whatever currency you might have active.

Also notice that my input currency is EUR, your might be different depending on the admin configuration.

app/design/frontend/[Your Theme]/template/checkout/cart.phtml

<?php 
     $freeshipping_data = floatval(Mage::getStoreConfig('carriers/freeshipping/free_shipping_subtotal'));
			
     $converted_value = Mage::helper('directory')->currencyConvert($freeshipping_data, 'EUR', Mage::app()->getStore()->getCurrentCurrencyCode());
		    
    if($this->getQuote()->getSubtotal() >= $converted_value){ /* You could also use $_product->getPrice() >= $converted_value if you were in the product detail page*/ 
	   
	   echo $this->__('This Cart has Free Shipping!'); 
	
    }else{
          echo "Add ".Mage::helper('checkout')->formatPrice($converted_value - $this->getQuote()->getSubtotal())."and you will have Free Shipping";
    }

?>Code language: HTML, XML (xml)

You can either show this on the cart or in the detail page. You could use $_product->getPrice() to retrieve the product price.

Tip

Enable the Magento Path Hints 😉

Comments

  1. Adam says:

    More easier solution for users without free shipping module:

    
    		getQuote()->getSubtotal(), -1)+1;
    					
    			if($this->getQuote()->getSubtotal() >= 1500){
    			   
    			   echo $this->__('<strong>Congrats</strong>, you have free shipping, now!'); 
    			
    			}
    			
    			else {
    				  echo "TIP: Add $<strong>".  $mycalculation . " Kč</strong> to your order to get Free Shipping!";
    			}
    		 
    		?>
    
    Code language: PHP (php)
  2. Alex says:

    Hi all,

    I’m from german, we have 2 Tax 19% and 7% tax, how can I change that in PHP code?

    Regards

    1. Rick says:

      Hi Alex,

      I guess it depens on the client, right?

      You need to use diffent customer types and assing each Tax type.

      You can do it all using the Admin.

      Let me know how it goes.

      Rick

  3. Sander says:

    Hi all, I am back 🙂 I just found out that he is getting the wrong amount. If you have any discount on your products he doesn’t use them.

    Is there a way to get the Grandtotal including discount and tax?

    1. Wouter says:

      Hi Sander, did you manage to solve this? I face the same issues.
      Thanks in advance.

  4. Peter says:

    Hi,
    I am new on magento
    I am using magento 1.5 and free-shipping option
    is there a way to set the delivery date to +1 day
    that means if a client buy today it can only select a date from tomorow.

    thank you in advance for the answer.

    1. Rick says:

      Hi Peter, I’m not sure what your question is.

      Regards

  5. Andy says:

    Hi,

    had this Topic today…

    width this Snippet you can get the amount from the Freeshipping-Modul in the Backend

    
    <?php 
    $freeshipping_data = floatval(Mage::getStoreConfig('carriers/freeshipping/free_shipping_subtotal'));
    ?>
    Code language: HTML, XML (xml)
    
    <?php 
    $freeshipping_data = floatval(Mage::getStoreConfig('carriers/freeshipping/free_shipping_subtotal'));
    
    $free_delivery=$freeshipping_data-$this->getQuote()->getSubtotal()*1.19;
    
          if ($free_delivery<0){
            echo "This Cart has Free Shipping!";
         }else{
            echo "Bestel nog ".Mage::helper('checkout')->formatPrice($free_delivery)." aan producten  en wij verzenden uw producten gratis";
         }
    ?>
    Code language: HTML, XML (xml)
    1. Rick says:

      Hi guys,

      I just wanted to let you know I’ve updated the post above with a better solution. It now converts the currency! 😉

      Cheers.

    2. Simon says:

      Ok, this code takes the free shipping amount from backend, but it takes it as amount and is still not respecting the currencies. If I havee free shipping from 100 Euro and change currency to USD, it won’t show the free shipping from 132$ (if 100€ = 132$) but from 100$.
      So by now, what I am doing is showing it only for the main currency I use, which is Euro. I inserted this line on the top of your snippet:

      if(Mage::app()->getStore()->getCurrentCurrencyCode() == "EUR") { // show only if currency is EUR Code language: PHP (php)
  6. Sander says:

    Jeej I just solved it by adding the 19% tax manually

    
    <?php $free_delivery=100-$this->getQuote()->getSubtotal()*1.19;
    
          if ($free_delivery<0){
            echo "This Cart has Free Shipping!";
         }else{
            echo "Bestel nog ".Mage::helper('checkout')->formatPrice($free_delivery)." aan producten  en wij verzenden uw producten gratis";
         }
    ?>
    Code language: HTML, XML (xml)
    1. Rick says:

      Well, I’m glad it worked out! 🙂

  7. Sander says:

    Hmm maybe thats my problem. If I put in 100 for free shipping is that then in dollars? Can not understand why my calculation is incorrect.

    1. Rick says:

      I’ve updated the post with the currency converter method!

  8. simon says:

    I again, thank you for clarifying the tax issue.

    Back to the currency thing, anyone got an idea on how to make it work with more currencies? the problem I stated a few comments above is still there.

    thanks

  9. Sander says:

    Sorry Rick but I am not sure what to do. So this is the code I use now

    <?php $free_delivery=100-$this->getQuote()->getSubtotal();
          if ($free_delivery<0){
            echo "This Cart has Free Shipping!";
         }else{
            echo "Bestel nog ".Mage::helper('checkout')->formatPrice($free_delivery)." aan producten  en wij verzenden uw producten gratis";
         }
    ?>Code language: HTML, XML (xml)

    do you mean doing something like this?

    <?php $free_delivery=100-$this->getQuote()->getSubtotal();
    $totals = $this->getQuote()->getTotals();
    $subtotal = $totals["subtotal"]->getValue();
    
    // print everything
    
    print_r($totals);
    
          if ($free_delivery<0){
            echo "This Cart has Free Shipping!";
         }else{
            echo "Bestel nog ".Mage::helper('checkout')->formatPrice($free_delivery)." aan producten  en wij verzenden uw producten gratis";
         }
    ?>Code language: HTML, XML (xml)
  10. Sander says:

    I only get errors when doing this 🙂

    1. Rick says:

      The new code I posted?

      What does it says?

  11. Sander says:

    Thanks Rick, Sorry but where do I need to put this? Below Subtotal?

    1. Rick says:

      In the same place you put the other code.

  12. Sander says:

    Do you know how I can get the subtotal inlcuding tax?.
    He is now doing the calculation based on the non tax amount wich is not correct.

    I tried getSubtotalInclTax but that doesn’t work

    Thanks for your help
    Sander

    1. Rick says:

      Hi Sander,

      Try this and let’s see what it returns 🙂

      
      $totals = $this->getQuote()->getTotals();
      $subtotal = $totals["subtotal"]->getValue();
      
      // print everything
      
      print_r($totals);
      
      Code language: PHP (php)
  13. simon says:

    Hi, what about when working with multiple currencies? if I set the amount to 100, it will be 100 for $, € and £. I’m sure working with some code from the currencies.php should be the answer

    thanks for the comments

    1. simon says:

      Sorry, that was working perfectly well, indeed!

      thank you very much for your contribution.

      Now I’m trying to display it now on header.

  14. leo says:

    i think it’d better to use

    $this->__(‘some texts’);

    instead of just echo directly, it comforts you on translation later.

  15. alancory says:

    Thanks for the Post, thanks for your useful Post. I will come back later !Thanks for the Post, thanks for your useful Post. I will come back later !

Leave a Reply

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