1

I'm looking to modify a cool little snippet of PHP that I found to use in my cart to show the customer how much more they have to spend to get free shipping. However, I need to add statements to it doesn't show it to customers in a particular customer group and country.

<?php if ($this->getQuote()->getSubtotal() < 50): ?>
<?php $subtotalamt = $this->getQuote()->getSubtotal(); ?>
<?php $freeshipamt = 50; ?>
<?php $sumtotal = $freeshipamt - $subtotalamt; ?>
<?php Mage::helper('checkout')->formatPrice($sumtotal); ?>
<p>You are just <span>$<?php print ($sumtotal); ?></span> 
away from earning free shipping!</p>
<?php endif ?>

I'm lost as to what I need to add to this to check for the customer group and and country.

5
  • country belongs to shipping country? Commented Jul 8, 2015 at 19:39
  • Yes, it would be shipping country. I'm only planning on using this script on my checkout page (not cart).
    – Eric Fox
    Commented Jul 8, 2015 at 19:48
  • In which template you have tried this code? Commented Jul 8, 2015 at 19:59
  • I use One Step Checkout from Magestore.com, I have the code placed inside of the shipping_method.phtml file. I tested the code as is, and it works, but I need to disable it for my wholesale customer group and anyone outside of the United States.
    – Eric Fox
    Commented Jul 8, 2015 at 20:05
  • check my answer Commented Jul 8, 2015 at 20:56

1 Answer 1

2

Try the below code, it works

<?php if ($this->getQuote()->getSubtotal()<50): ?>
    <?php $subtotalamt = $this->getQuote()->getSubtotal(); ?>
    <?php $freeshipamt = 50; ?>
    <?php $sumtotal = $freeshipamt - $subtotalamt; ?>
    <?php Mage::helper('checkout')->formatPrice($sumtotal); ?>
    <?php  $loggedIn = Mage::getSingleton('customer/session')->isLoggedIn(); ?>
    <?php if($loggedIn):
                $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); 
                $groupname = Mage::getModel('customer/group')->load($groupId)->getCustomerGroupCode();
                $shippingCountryId = $this->getQuote()->getShippingAddress()->getCountryId();
                if(($groupname != "Wholesale") && ($shippingCountryId == "US")):?>
                        <p>You are just <span>$<?php print ($sumtotal); ?></span> 
                        away from earning free shipping!</p>

                <?php endif ?>  
    <?php endif; ?>
<?php endif ?>
4
  • Hi saravanavelu, thanks for working this for me, however it's working reverse of what I want. It's showing the text ONLY to wholesale customers in the US. It needs to show only to customers who are not wholesale and/or country is not US.
    – Eric Fox
    Commented Jul 9, 2015 at 12:23
  • as per our conversation you noted as to disable it for wholesale customer group and outside US. Commented Jul 9, 2015 at 12:50
  • Hi saravanevelu, I actually tried it again and it did work. However, it only shows to customers who are logged in and who are not wholesale or outside of the US. How can I change it to where if the customer is not logged in, then it would show?
    – Eric Fox
    Commented Jul 10, 2015 at 1:34
  • If not logged in, u can't get the customer group. Commented Jul 10, 2015 at 2:33

Your Answer

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

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