hide cms block on checkout page if customer logged in
-
29-09-2020 - |
Domanda
I want to hide my CMS block if customer is logged in. This is how my block is added to OPC page via local.xml
file.
<opc_index_index>
<reference name="content">
<block type="cms/block" name="cart_sinup" before="_">
<action method="setBlockId">
<block_id>signup</block_id>
</action>
</block>
</reference>
</opc_index_index>
Note: I cannot use <customer_logged_in>
because I want this only in opc_index_index page.
Soluzione 2
I have solved this problem by replacing the following xml
<opc_index_index>
<reference name="content">
<block type="cms/block" name="cart_sinup" before="_">
<action method="setBlockId">
<block_id>signup</block_id>
</action>
</block>
</reference>
</opc_index_index>
with
<opc_index_index>
<reference name="content">
<block type="core/template" name="cart_sinup" before="_" template="ds/regaddress/opc_signup_wrapper.phtml" />
</reference>
</opc_index_index>
in my local.xml and then create a new template file
app/design/frontend/package/theme/template/ds/regaddress/opc_signup_wrapper.phtml
and add this code in it.
<?php
if(!Mage::getSingleton('customer/session')->isLoggedIn()){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('signup')->toHtml();
}
?>
What I'm doing here is rendering my cms_block in template file with the user logged in check and then adding this block via xml.
Cheers :)
Altri suggerimenti
You can do this simply by using a css.
when you create a CMS Block assign a class or id to its container like <div class="customer_login_condition">
and on app\design\frontend\<YOUR_PACKAGE>\<YOUR_THEME>\template\page\html\footer.phtml
add the css like following at the bottom of phtml.
<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()){
?>
<style>
.customer_login_condition {display:none;}
</style>
<?php
}
?>
Hope this helps you.
In success.phtml you could do:
if(!Mage::getSingleton('customer/session')->isLoggedIn()) {
echo $this->getChildHtml('cart_sinup');
}
Typo in "sinup", but I just matched yours.
This will output the block if customer is not signed in, if they are signed in it will simply continue.