I am making a Free Shipping top bar, i have added code in header.phtml which is located in app/design/frontend/mytheme/mytheme05/template/page/html/header.phtml

My Code is :

<div id= "um" class="container" style="text-align: center; font-weight: bold; ">

$grand= $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); 

$count = (int) filter_var($grand, FILTER_SANITIZE_NUMBER_INT);

$umer= 1500;
$total= $umer-$count;
if ($count < $umer)
    echo "Free Shipping on $total";

    echo "Free Shipping Enjoy"; 


I want to refresh this div when Add to cart Button is press.

The code is located in :


Code is here`

<div class="actions-cart">
<?php if(in_array("cart", $actions)):?>
    <?php if($_product->isSaleable()): ?>
        <button type="button" title="<?php echo $this->__('Add to cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Umer') ?></span></span></button>
    <?php else: ?>
        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
    <?php endif; ?>
<?php endif; ?>

I want to refresh that div on onclick Button.

How I can do this ?

This is the Header which I want to update. It is working fine if I refresh the page

  • The better is to do it with Ajax, now you want to do it with Ajax or even if you reload the page does not bother you ?
    – PЯINCƎ
    Jul 5, 2017 at 22:34
  • Can you please tell me how I can do with this Ajax
    – Umer
    Jul 5, 2017 at 23:05

1 Answer 1


If you want to do this on reload the page, you have to add location.reload(); on onclick add to cart button, But i confirm that the best way is to do it with AJAX

For the product page for exemple:


<button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="btn-cart btn btn-primary btn-sm" onclick="productAddToCartForm.submit(this); location.reload();"><?php echo $buttonTitle ?></button>

With Ajax :

function reload(url){
       $.get(url, function(data){      // $.get will get the content of the page defined in url and will return it in **data** variable 

        var url = 'http://example.com/somepage.html';
        reload(url);  // this calls the reload function


Or you can do some load() function something like :

$("#myDiv").load(location.href+" #myDiv>*","");


  • I want to only refresh that free shipping part which is in header instead of whole page
    – Umer
    Jul 5, 2017 at 23:20
  • Look my update please
    – PЯINCƎ
    Jul 6, 2017 at 0:35
  • you're welcome ;)
    – PЯINCƎ
    Jul 7, 2017 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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