1

I have a function to get the customer group ID and in my phtml file if it equals the customer group id I show content. The issue is that when I test it in a production environment the content doesn't seem to show but on a development environment it does. I thought pages were built by Customer Group

app/code/{vendor}/{module}/Block/{file}.php

public function __construct(
    ...
    \Magento\Customer\Model\Session $customerSession
    ...
) {
   ...
    $this->_customerSession = $customerSession;
   ...
}

public function getGroupId()
{
    if($this->_customerSession->isLoggedIn()){
        return $this->_customerSession->getCustomer()->getGroupId();
    }

    return '';
}

app/design/frontend/{Vendor}/{Theme}/{module}/{template}/{file}.phtml

     <?php if($block->getGroupId() == 1): ?>
        <p> content messaging </p>
    <?php endif; ?>

Your Answer

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

Browse other questions tagged or ask your own question.