cancel
Showing results for 
Search instead for 
Did you mean: 

Hide attribute for not logged in users?

SOLVED

Hide attribute for not logged in users?

Hi,

 

Is it possible to hide a attribute, for not logged in users? So only the logged in users can see the attribute on the product?

 

- Kristoffer

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Hide attribute for not logged in users?

You're probably looking for something similar to this:

 

<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
	Login to see
<?php else: ?>
	<h2><?php echo $this->__("Additional Information") ?></h2><table class="data-table" id="product-attribute-specs-table"><col width="25%" />
        <col /><tbody>
        <?php foreach ($_additional as $_data): ?>
            <tr>
                <th class="label"><?php echo $this->escapeHtml($this->__($_data["label"])) ?></th>
                <td class="data"><?php echo $_helper->productAttribute($_product, $_data["value"], $_data["code"]) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody></table>
	<script type="text/javascript">decorateTable("product-attribute-specs-table")</script>
<?php endif; ?>

View solution in original post

6 REPLIES 6

Re: Hide attribute for not logged in users?

Hi @kripalmen

 

Which attributes you want to hide and at which places? Most probably, you need to customize the magento coding for your requirements.

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

Re: Hide attribute for not logged in users?

Hi @theMageComp

 

Its a attribute I add by my self. It is just a text field with a extra price, that is added to the product. And this field I want to hide, for guest users, so it only shows for users who is logged in.

 

Thanks.

Re: Hide attribute for not logged in users?

You do something like this.

At the place where you code for displaying the attribute on frontend. Put the following condition before your code.

<?php
    if(!Mage::getSingleton('customer/session')->isLoggedIn()){
        //not logged in
    }else{
        // logged in
    }
?>
Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

Re: Hide attribute for not logged in users?

Hi @theMageComp

 

Thank you for the help Smiley Happy

I have know tried to do this, see the code below:

 

<?php
    if(!Mage::getSingleton('customer/session')->isLoggedIn()){
		echo 'Login to see';
    }else{
		echo '<h2><?php echo $this->__("Additional Information") ?></h2><table class="data-table" id="product-attribute-specs-table"><col width="25%" />
        <col /><tbody>
        <?php foreach ($_additional as $_data): ?>
            <tr>
                <th class="label"><?php echo $this->escapeHtml($this->__($_data["label"])) ?></th>
                <td class="data"><?php echo $_helper->productAttribute($_product, $_data["value"], $_data["code"]) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody></table><?php endif;?><script type="text/javascript">decorateTable("product-attribute-specs-table")</script>';
    }
?>

It works fine when I´m not logged in, the it shows the text: Login to see.

But when I logge in, then It only shows code :

 

 

 

 

Re: Hide attribute for not logged in users?

You're probably looking for something similar to this:

 

<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
	Login to see
<?php else: ?>
	<h2><?php echo $this->__("Additional Information") ?></h2><table class="data-table" id="product-attribute-specs-table"><col width="25%" />
        <col /><tbody>
        <?php foreach ($_additional as $_data): ?>
            <tr>
                <th class="label"><?php echo $this->escapeHtml($this->__($_data["label"])) ?></th>
                <td class="data"><?php echo $_helper->productAttribute($_product, $_data["value"], $_data["code"]) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody></table>
	<script type="text/javascript">decorateTable("product-attribute-specs-table")</script>
<?php endif; ?>

Re: Hide attribute for not logged in users?

Hi @zenenjaimes

 

Thank you.

The code didnt show the attribute, so I did a little change in your code and know it works.

I will post the code here, if any body else need it:

 

<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
	Login to see
<?php elseif($_additional = $this->getAdditionalData()): ?>
    <h2><?php echo $this->__('Additional Information') ?></h2>
    <table class="data-table" id="product-attribute-specs-table">
        <col width="25%" />
        <col />
        <tbody>
        <?php foreach ($_additional as $_data): ?>
            <tr>
                <th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
                <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    <script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>