Magento: Accessing Customer Session

I needed to create some custom shipping functionality within Magento today which would charge wholesale customers $5.00 flat rate, and all other customers got free shipping. This required having to access the customer group number. Wholesale customers are have a group id of 2.

So, I wrote a simple if statement in /template/checkout/onepage/shipping_method/available.phtml to check.

You may also want to simply check if users are logged in or not but don’t really need their customer group number. Here is how you can easily access this information from anywhere:

Check if User is Logged In

# Returns boolean
$logged_in = Mage::getSingleton( 'customer/session' )->isLoggedIn();

Get Customers Group ID

$group = Mage::getSingleton('customer/session')->getCustomerGroupId();

This entry was posted in Magento. Bookmark the permalink.

3 Responses to Magento: Accessing Customer Session

  1. SUDEESH says:


  2. Ehsan says:

    Thanks , It help me out

  3. dimi says:

    its so cool that you share your knowledge with us.
    i’ve also started posting wiki articles on magento.
    Keep it up! You help a lot of people!

    warm regards