Hello everyone! First of all...sorry for my bad english.
Anybody knows a code or something to hide or modify Add to cart button if product stock is 0? I mean on all pages the product is shown.
Please help!
Anybody knows a code or something to hide or modify Add to cart button if product stock is 0? I mean on all pages the product is shown.
Please help!
Hello,
You will need to do some modification.
First of all, open the file catalog/product/product.php and add the following code
after
In final, the code should look like
Then open the file view/theme/YOUR_THEME/template/product/product.tpl
Change the following code from
to
Please note that 'YOUR_THEME' is the theme folder you are using. In case you are using the original theme of OpenCart, then the folder is default
Hope it helps.
Best Regards,
OpenTeam
You will need to do some modification.
First of all, open the file catalog/product/product.php and add the following code
Code: Select all
$data['stock_quantity'] = $product_info['quantity'];
Code: Select all
$data['points'] = $product_info['points'];
Code: Select all
$data['points'] = $product_info['points'];
$data['stock_quantity'] = $product_info['quantity'];
Change the following code from
Code: Select all
<button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block"><?php echo $button_cart; ?></button>
Code: Select all
<?php if($stock_quantity > 0) { ?>
<button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block"><?php echo $button_cart; ?></button>
<?php } ?>
Hope it helps.
Best Regards,
OpenTeam
Works perfectly with anything I want to hide if product stock is 0 on the product page...but in categories? Home page? Can I do this every time I want to hide the button?
I recently discovered that it made to disappear the button on all products...even those who were in stock...the code doesn't work correctly
For category page, you need add code to file category.php and category.tpl.avramalex111 wrote:Works perfectly with anything I want to hide if product stock is 0 on the product page...but in categories? Home page? Can I do this every time I want to hide the button?
You can try this guide.
1. Open file category.php (catalog/controller/product/category.php)
2. Find :
Code: Select all
$data['products'][] = array(]]></search>
Code: Select all
'quantity' => $result['quantity'],
5. Find :
Code: Select all
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
Code: Select all
<?php if ($product['quantity'] > 0) { ?>
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
<?php } ?>
(catalog/controller/module/featured.php) and featured.tpl (catalog/view/theme/your_theme/template/module/featured.tpl).
The code doesn't work correctly...I discovered this on In stock products...I mean the first code from OpenTeam
opencartboost wrote:For category page, you need add code to file category.php and category.tpl.avramalex111 wrote:Works perfectly with anything I want to hide if product stock is 0 on the product page...but in categories? Home page? Can I do this every time I want to hide the button?
You can try this guide.
1. Open file category.php (catalog/controller/product/category.php)
2. Find :3. Add after :Code: Select all
$data['products'][] = array(]]></search>
4. Open file category.tpl (catalog/view/theme/your_theme/template/product/category.tpl)Code: Select all
'quantity' => $result['quantity'],
5. Find :6. Replace with:Code: Select all
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
For home page. that is dependent your module, if you are using featured module, you need add code to file featured.phpCode: Select all
<?php if ($product['quantity'] > 0) { ?> <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button> <?php } ?>
(catalog/controller/module/featured.php) and featured.tpl (catalog/view/theme/your_theme/template/module/featured.tpl).
I am create vqmod file to hide add to cart button when product quantity is 0 for category page and featured module.
That code based on default theme.
The result should like this (see at samsung galaxy image product)
http://awesomescreenshot.com/00853jfff9
http://awesomescreenshot.com/06253jfj64
That code based on default theme.
The result should like this (see at samsung galaxy image product)
http://awesomescreenshot.com/00853jfff9
http://awesomescreenshot.com/06253jfj64
It's not working after I modified the xml file with my theme name
opencartboost wrote:I am create vqmod file to hide add to cart button when product quantity is 0 for category page and featured module.
That code based on default theme.
The result should like this (see at samsung galaxy image product)
http://awesomescreenshot.com/00853jfff9
http://awesomescreenshot.com/06253jfj64
That mean code in file .tpl not same.avramalex111 wrote:It's not working after I modified the xml file with my theme name
opencartboost wrote:I am create vqmod file to hide add to cart button when product quantity is 0 for category page and featured module.
That code based on default theme.
The result should like this (see at samsung galaxy image product)
http://awesomescreenshot.com/00853jfff9
http://awesomescreenshot.com/06253jfj64
Find code add to cart button for your theme, and add conditional for product quantity > 0.
I tried to use the code here, it works a sort of..
1. I want to use it for OC 2.0.2.0.
2. I don't have path, catalog/product/product.php, I can find this path: catalog/controller/product/product.php is this the same file?
3. In product.tpl (own theme) don't have the code:
<button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block"><?php echo $button_cart; ?></button>
this looks almost the same but it is not:
<button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block button-left"><?php echo $button_cart; ?></button>
4. When I play with this not correct code, there is a strange effect, the checkout button is called add to cart but goes to checkout
Someone help me??
1. I want to use it for OC 2.0.2.0.
2. I don't have path, catalog/product/product.php, I can find this path: catalog/controller/product/product.php is this the same file?
3. In product.tpl (own theme) don't have the code:
<button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block"><?php echo $button_cart; ?></button>
this looks almost the same but it is not:
<button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block button-left"><?php echo $button_cart; ?></button>
4. When I play with this not correct code, there is a strange effect, the checkout button is called add to cart but goes to checkout
Someone help me??
Hi
I am using this code in my product page and it works perfect but is there a way to display a out of stock button where the add to cart would be, at the moment it hides the add to cart button but would be good to show a out of stock button instead
the url is http://www.forsweetsake.co.uk/hostess-raspberry-zingers
How can I get it to work on the category page and featured module as well, I tried the xml file but that don;t work, I am using a custom theme in my 2.0.3.1 store called shovelhead
Thank you in advance
UPDATE: Sorry got it working now, if anyone needs something similar, let me know and will share my coding
I am using this code in my product page and it works perfect but is there a way to display a out of stock button where the add to cart would be, at the moment it hides the add to cart button but would be good to show a out of stock button instead
the url is http://www.forsweetsake.co.uk/hostess-raspberry-zingers
How can I get it to work on the category page and featured module as well, I tried the xml file but that don;t work, I am using a custom theme in my 2.0.3.1 store called shovelhead
Thank you in advance
UPDATE: Sorry got it working now, if anyone needs something similar, let me know and will share my coding
Hi ianhaney. You can send me your code? I am try to do something similarianhaney wrote: ↑Sun May 07, 2017 4:58 pmHi
I am using this code in my product page and it works perfect but is there a way to display a out of stock button where the add to cart would be, at the moment it hides the add to cart button but would be good to show a out of stock button instead
the url is http://www.forsweetsake.co.uk/hostess-raspberry-zingers
How can I get it to work on the category page and featured module as well, I tried the xml file but that don;t work, I am using a custom theme in my 2.0.3.1 store called shovelhead
Thank you in advance
UPDATE: Sorry got it working now, if anyone needs something similar, let me know and will share my coding
Who is online
Users browsing this forum: No registered users and 74 guests