[HOWTO] Opencart 4 Disable Add to cart / Paypal Buttons when zero stock.
Posted: Thu Sep 01, 2022 4:29 pm
This is a simple mod that takes 2 minutes.
All we are doing is pulling the quantity from the database into a data parameter,
Then switching on the add to cart buttons of that value is not zero.
First we pull the quantity value from the database and into a data parameter:
In file:/catalog/controller/product/product.php
Find:
Add this line before it:
Save and close the file.
Then we switch the buttons on and off depending on if the value is zero or not with a simple 'if' statement
In file /catalog/view/template/product/product.twig
Find:
Add this line before it:
Add this line after it:
I would have posted it in the OC4 section but it looks like I don't have permissions to post there.
Cheers.
Psi
All we are doing is pulling the quantity from the database into a data parameter,
Then switching on the add to cart buttons of that value is not zero.
First we pull the quantity value from the database and into a data parameter:
In file:/catalog/controller/product/product.php
Find:
Code: Select all
if ($product_info['quantity'] <= 0) {
Code: Select all
$data['stockb'] = $product_info['quantity'];
Then we switch the buttons on and off depending on if the value is zero or not with a simple 'if' statement
In file /catalog/view/template/product/product.twig
Find:
Code: Select all
<button type="submit" id="button-cart" class="btn btn-primary btn-lg btn-block">{{ button_cart }}</button>
Code: Select all
{% if stockb > 0 %}
Code: Select all
{% endif %}
Cheers.
Psi