How to disable button in an if condition

How do i disable a button if the prod_quantity == 0?

<?php
    $prod_qty = $row['prod_quantity'];

            if ($prod_qty == '0'){
                echo "<h1>sold out</h1>";
            }
?>

and here is the button that i need to be disabled when prod_qty == 0

<input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row["prod_id"]?>)" />

Answer

Add an if condition to the button to set the property as disabled if $prod_qty == '0' like shown below :

<input type="button" value="Add to Cart" <?php if ($prod_qty == '0'){ ?> disabled <?php   } ?> onclick="addtocart(<?php echo $row["prod_id"]?>)" />

Leave a Reply

Your email address will not be published. Required fields are marked *