CodeIgniter Forums
Hide item price if user is not logged in - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3)
+--- Thread: Hide item price if user is not logged in (/showthread.php?tid=71168)



Hide item price if user is not logged in - chanceymwa - 07-15-2018

I wanna hide the price from unregistered  and registered users that are not logged in  my code 

I have used the  same syntax  to hide links as below and works perfect
PHP Code:
                    <?php 
                        
if($obj->hasloggedin)
                        {
                            echo 
'<a href="catalogue">CATALOGUES</a>';
                        }
                        else 
                        {
                            echo 
'';                
                        }
                    
?>



but i seem not to get around nesting another if statement  under another if statement.(brings a blank page Undecided )

anyone with an idea to resolve this Confused
PHP Code:
            <?php 
            
if($obj->hasloggedin)
            {
                echo 
'
                <form class="form-horizontal qtyFrm" onsubmit = "addtocartwithquantity($(this).attr('
action')+'/'+$('#qty').val(),this,event);" action = "<?php echo  base_url().'cart/addtocart/'.$obj->product['product_id'];?>">
                  <div class="control-group">
                    <label class="control-label">
                        <?php 
                            
if($obj->product["discount_status"] == "1")
                            {
                                echo 
'
                                    <strong>Price&nbsp;:</strong>&nbsp;<span class = "price-number" style = "text-decoration:line-through;color : red;">R '
.$obj->product["product_price"].'</span><br />
                                    <strong>Discount&nbsp;Price&nbsp;:</strong>&nbsp;<span class = "price-number" style = "">R'
.$obj->product["discount_price"].' </span>
                                '
;
                            }
                            else
                            {
                                echo 
'<strong>Price&nbsp;:</strong>&nbsp;<span class = "price-number">R '.$obj->product["product_price"].'</span>';
                            }
                        
?>
                    </label>
                    <div class="controls" style="clear: both;margin-left: 0px;">
                        <input type="number" id = "qty" class="span1 num_inc" placeholder="Qty."/>
                      <button type="submit" class="btn btn-large btn-success pull-right"> Add to cart <i class=" icon-shopping-cart"></i>
                      </button>
                    </div>                    
                  </div>
                </form>
                ';

                
                echo '<li class="">';
            }
            else 
            {
                echo '<li class="">';                
            }
        ?>



RE: Hide item price if user is not logged in - jreklund - 07-15-2018

You have syntax errors. You need a developing server with error logs and a PHP editor that support syntax.

PHP Code:
<?php 
if($obj->hasloggedin)
{
?>
    <form class="form-horizontal qtyFrm" onsubmit = "addtocartwithquantity($(this).attr('action')+'/'+$('#qty').val(),this,event);" action = "<?php echo  base_url().'cart/addtocart/'.$obj->product['product_id'];?>">
      <div class="control-group">
        <label class="control-label">
            <?php 
                
if($obj->product["discount_status"] == "1")
                {
                    echo 
'
                        <strong>Price&nbsp;:</strong>&nbsp;<span class = "price-number" style = "text-decoration:line-through;color : red;">R '
.$obj->product["product_price"].'</span><br />
                        <strong>Discount&nbsp;Price&nbsp;:</strong>&nbsp;<span class = "price-number" style = "">R'
.$obj->product["discount_price"].' </span>
                    '
;
                }
                else
                {
                    echo 
'<strong>Price&nbsp;:</strong>&nbsp;<span class = "price-number">R '.$obj->product["product_price"].'</span>';
                }
            
?>
        </label>
        <div class="controls" style="clear: both;margin-left: 0px;">
            <input type="number" id = "qty" class="span1 num_inc" placeholder="Qty."/>
          <button type="submit" class="btn btn-large btn-success pull-right"> Add to cart <i class=" icon-shopping-cart"></i>
          </button>
        </div>                    
      </div>
    </form>
    <li class="">
<?php
}
else 
{
    echo 
'<li class="">';                
}
?>



RE: Hide item price if user is not logged in - chanceymwa - 07-16-2018

Thank  i have used the syntax below and it working  perfect
PHP Code:
                    <!-- testin code here -->
                                    <?
php 
                                        
if($obj->isloggedin
                                            {if(
$obj->product["discount_status"] == "1")
                                                {
                                                echo 
'<strong>Price&nbsp;:</strong>&nbsp;<span class = "price-number" style = "text-decoration:line-through;color : red;">R '.$obj->product["product_price"].'</span><br />

                                                    <strong>Discount&nbsp;Price&nbsp;:</strong>&nbsp;<span class = "price-number" style = "">R'
.$obj->product["discount_price"].' </span>';
                                                }else
                                                {
                                                echo
'<strong>Price&nbsp;:</strong>&nbsp;<span class = "price-number">R '.$obj->product["product_price"].'</span>';
                                                };
                                            }
                                        else 
                                        {
                                        echo 
'whatever /chilichonse / redirect to login page/ login to see price'
                                         
;                
                                        }
                                    
?>
                    <!-- testing my code here --> 



RE: Hide item price if user is not logged in - InsiteFX - 07-17-2018

They should not see anything if that information doe's not belong to them.