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

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 😉

26 Responses to “Add XX to Cart for Free Shipping – Magento”

  1. alancory July 20, 2011 at 8:47 am #

    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 !

  2. leo November 15, 2011 at 3:20 am #

    i think it’d better to use

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

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

  3. simon December 31, 2011 at 4:57 pm #

    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

    • simon December 31, 2011 at 5:19 pm #

      Sorry, that was working perfectly well, indeed!

      thank you very much for your contribution.

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

  4. Sander January 5, 2012 at 3:21 pm #

    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

    • Rick January 5, 2012 at 4:15 pm #

      Hi Sander,

      Try this and let’s see what it returns 🙂

      [code]
      $totals = $this->getQuote()->getTotals();
      $subtotal = $totals["subtotal"]->getValue();

      // print everything

      print_r($totals);

      [/code]

  5. Sander January 5, 2012 at 4:17 pm #

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

    • Rick January 5, 2012 at 8:30 pm #

      In the same place you put the other code.

  6. Sander January 5, 2012 at 9:56 pm #

    I only get errors when doing this 🙂

    • Rick January 5, 2012 at 10:20 pm #

      The new code I posted?

      What does it says?

  7. Sander January 5, 2012 at 10:37 pm #

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

    [code]<?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]

    do you mean doing something like this?

    [code]<?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]

  8. simon January 5, 2012 at 11:48 pm #

    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 January 6, 2012 at 8:05 am #

    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.

    • Rick April 11, 2013 at 11:53 pm #

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

  10. Sander January 6, 2012 at 9:19 am #

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

    [code]
    <?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]

    • Rick January 6, 2012 at 12:07 pm #

      Well, I’m glad it worked out! 🙂

  11. Andy January 27, 2012 at 2:06 am #

    Hi,

    had this Topic today…

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

    [code]
    <?php
    $freeshipping_data = floatval(Mage::getStoreConfig(‘carriers/freeshipping/free_shipping_subtotal’));
    ?>
    [/code]

    [code]
    <?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]

    • Simon January 28, 2012 at 6:36 pm #

      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:
      [code]if(Mage::app()->getStore()->getCurrentCurrencyCode() == "EUR") { // show only if currency is EUR [/code]

    • Rick April 11, 2013 at 11:50 pm #

      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.

  12. Peter February 3, 2012 at 2:13 pm #

    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.

    • Rick February 3, 2012 at 3:34 pm #

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

      Regards

  13. Sander April 28, 2012 at 10:32 pm #

    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?

    • Wouter September 11, 2012 at 10:07 am #

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

  14. Alex August 4, 2012 at 7:00 pm #

    Hi all,

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

    Regards

    • Rick August 4, 2012 at 7:06 pm #

      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

  15. Adam April 6, 2016 at 9:02 pm #

    More easier solution for users without free shipping module:

Leave a Reply

Add <code> Some Code </code> by using this tags.