Jump to content

Cart Help, Changing Button Disply


dvs12c

Recommended Posts

I am using OPENCART and i would like to have my "Add To Cart" button read "Pre Order" when the stock is 0. This is just for now i will want to change it later to make the button reflect certain stock statuses.

 

For now i would like some help cleaning this up so it work :P

 

 

$x = "PRE ORDER";
define("X");

<?php
if ($product_info['quantity'] <= 0)
{      
    $x = "<?php echo $button_cart; ?>"          
}
else      
{      
    echo $x
      }
      
?> 
              
            <a id="button-cart" class="button"><span>$x</span></a></div>

Link to comment
https://forums.phpfreaks.com/topic/251308-cart-help-changing-button-disply/
Share on other sites

This is the original code that.

 

Where i want <?php echo $button_cart; ?> to reflect the IF outcome

 

<div class="cart">
        <div><?php echo $text_qty; ?>
          <input type="text" name="quantity" size="2" value="<?php echo $minimum; ?>" />
          <input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
           <a id="button-cart" class="button"><span><?php echo $button_cart; ?></span></a></div>
        <div><span>   <?php echo $text_or; ?>   </span></div>
        <div><a onclick="addToWishList('<?php echo $product_id; ?>');"><?php echo $button_wishlist; ?></a><br />
          <a onclick="addToCompare('<?php echo $product_id; ?>');"><?php echo $button_compare; ?></a></div>
        <?php if ($minimum > 1) { ?>
        <div class="minimum"><?php echo $text_minimum; ?></div>
        <?php } ?>
      </div>

 

    $x = "<?php echo $button_cart; ?>"          

You can't do that, you can't put PHP tags inside a PHP variable.  The <?php tag tells the server "this document is to be parsed with the PHP interpreter."  If you put it inside a PHP variable you'll just...break it.

 

define("X");

You can't do that either, this line serves absolutely no purpose.

 

<?php
if ($product_info['quantity'] <= 0)
{      
    echo $button_cart; 
}
else      
{      
    echo "PRE-ORDER";
}
      
?> 

Of course, you'll have to actually define a pre-order button instead of the bare string "pre-order"

Had some trouble using this where i wanted to, i have the following code working.

 

<?php if ($product_info['quantity'] <= 0) {?>
   	  <a id="button-cart" class="button"><span>PRE ORDER</span></a> 	 
<?php } ?>   

 

Problem is now it will hide the button when the stock is > 0, I would like an else statement for the following, i just dont know how to do it as im a php noob:

 

 <a id="button-cart" class="button"><span><php echo $button_cart; ?></span></a>

 

 

 

I am happy to do this another way if some one can see it from the second post of mine.

Sorted it out with the following

 

<?php if ($product_info['quantity'] <= 0){?>

 <a id="button-cart" class="button"><span>PRE ORDER</span></a> 

<?php } else { ?>
  
    <a id="button-cart" class="button"><span><?php echo $button_cart; ?></span></a>

<?php } ?>

 

 

Next will be to make PRE ORDER none static

 

Thanks for your help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.