dvs12c Posted November 17, 2011 Share Posted November 17, 2011 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 $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> Quote Link to comment https://forums.phpfreaks.com/topic/251308-cart-help-changing-button-disply/ Share on other sites More sharing options...
dvs12c Posted November 17, 2011 Author Share Posted November 17, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/251308-cart-help-changing-button-disply/#findComment-1288923 Share on other sites More sharing options...
ManiacDan Posted November 17, 2011 Share Posted November 17, 2011 $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" Quote Link to comment https://forums.phpfreaks.com/topic/251308-cart-help-changing-button-disply/#findComment-1288930 Share on other sites More sharing options...
dvs12c Posted November 17, 2011 Author Share Posted November 17, 2011 Ill give it a go. I have not done any PHP before thanks for cleaning it up. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/251308-cart-help-changing-button-disply/#findComment-1289041 Share on other sites More sharing options...
dvs12c Posted November 17, 2011 Author Share Posted November 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251308-cart-help-changing-button-disply/#findComment-1289144 Share on other sites More sharing options...
dvs12c Posted November 18, 2011 Author Share Posted November 18, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/251308-cart-help-changing-button-disply/#findComment-1289151 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.