I want a script that will subtract the real-time subtotal from a set dollar amount declared for free shipping that I can display in the drop-down mini cart on our site. Example Display: "You are $27.46 from free shipping."

This is based on a threshold of $99 for shipping with a subtotal of $71.54 in the cart.


I happened to find this solution and it works quite well in See http://svosolutions.com/blog/magento-display-amount-until-free-shipping/

I hope it is not bad form to post an outside link, but I had trouble getting the code to post just as code.

  • It's fine to post links but you should include a full answer in case the link breaks. – Holly Oct 10 '15 at 6:51
  • Well, it kind of worked. I noticed that the dollar amounts truncates any trailing second zero so $19.20 appears as $19.2. What is the solution to keep 2 decimal places at all times? – Scot Oct 10 '15 at 23:36
  • Holy, As I stated, the code would not just post as code. The page was processing the php and not actually showing the code. I also found a solution to my issue. If I use the code at the link above and then use this code, I get my trailing zero. Btw, I have no idea why it seems to be letting me post code in the comments, but not in the answer. <?php echo number_format(($sumtotal), '2', '.', ',');?> – Scot Oct 14 '15 at 2:32
  • Here is what I used: <?php $subtotalamt = $this->getQuote()->getSubtotal(); ?> <?php $freeshipamt = 99; ?> <?php $sumtotal = $freeshipamt - $subtotalamt; ?> <?php Mage::helper('checkout')->formatPrice($sumtotal); ?> <?php if ($this->getQuote()->getSubtotal() > 99): ?> <div class="free-shipping-earned"> <h6>Congratulations! You've earned free shipping!</h6> <?php else: ?> <div class="free-shipping"> <h6>You're <span>$<?php echo number_format(($sumtotal), '2', '.', ',');?></span> away from earning free shipping!</h6> <?php endif ?> </div> – Scot Oct 14 '15 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.