• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hide item price if user is not logged in

#1
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="">';                
            }
        ?>
Reply

#2
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="">';                
}
?>
Reply

#3
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 --> 
Reply

#4
They should not see anything if that information doe's not belong to them.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.