Add XX to Cart for Free Shipping – Magento

23 June 2011 by Rick ~ 20 Comments 2065 views

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

Paste the following code where you want to add the code.

I would suggest something like:

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

// Change the 290 with your own value
<?php $free_delivery=290-$this->getQuote()->getSubtotal();
      if ($free_delivery<0){
        echo "This Cart has Free Shipping!";
     }else{
        echo "Add ".Mage::helper('checkout')->formatPrice($free_delivery)."and you will have Free Shipping";
     }
?>

Tip

Enable the Magento Path Hints ;)

Subscribe by E-mail:

« »

20 Comments

  1. 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. i think it’d better to use

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

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

     
  3. 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

     
    • 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. 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

     
    • Hi Sander,

      Try this and let’s see what it returns :)

      $totals = $this->getQuote()->getTotals();
      $subtotal = $totals["subtotal"]->getValue();
      
      // print everything
      
      print_r($totals);
      
       
  5. Thanks Rick, Sorry but where do I need to put this? Below Subtotal?

     
  6. I only get errors when doing this :-)

     
  7. 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";
         }
    ?>

    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";
         }
    ?>
     
  8. 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. 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.

     
  10. 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";
         }
    ?>
    
     
  11. 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'));
    ?>
    
    <?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";
         }
    ?>
    
     
    • 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 
       
  12. 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.

     
  13. 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?

     

Add a Comment

Use [code] example piece of code [/code] to insert code into your comment.