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
Solved! Go to Solution.
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; ?>
Hi @kripalmen
Which attributes you want to hide and at which places? Most probably, you need to customize the magento coding for your requirements.
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.
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 } ?>
Hi @theMageComp
Thank you for the help
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 :
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; ?>
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;?>