Post by avramalex111 » Sat Jul 25, 2015 11:49 pm

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!

Newbie

Posts

Joined
Tue Jun 23, 2015 12:12 am

Post by OpenTeam » Sun Jul 26, 2015 4:50 am

Hello,

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'];
after

Code: Select all

$data['points'] = $product_info['points'];
In final, the code should look like

Code: Select all

$data['points'] = $product_info['points'];
$data['stock_quantity'] = $product_info['quantity'];
Then open the file view/theme/YOUR_THEME/template/product/product.tpl

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>
to

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 } ?>
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

User avatar
Active Member

Posts

Joined
Tue May 19, 2015 2:31 am

Post by avramalex111 » Sun Jul 26, 2015 7:55 pm

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?

Newbie

Posts

Joined
Tue Jun 23, 2015 12:12 am

Post by avramalex111 » Sun Jul 26, 2015 8:20 pm

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

Newbie

Posts

Joined
Tue Jun 23, 2015 12:12 am

Post by opencartboost » Sun Jul 26, 2015 8:36 pm

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?
For category page, you need add code to file category.php and category.tpl.
You can try this guide.
1. Open file category.php (catalog/controller/product/category.php)
2. Find :

Code: Select all

$data['products'][] = array(]]></search>
3. Add after :

Code: Select all

'quantity'	=> $result['quantity'],
4. Open file category.tpl (catalog/view/theme/your_theme/template/product/category.tpl)
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>
6. Replace with:

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 } ?>
For home page. that is dependent your module, if you are using featured module, you need add code to file featured.php
(catalog/controller/module/featured.php) and featured.tpl (catalog/view/theme/your_theme/template/module/featured.tpl).

Active Member

Posts

Joined
Thu Jul 09, 2015 5:59 am

Post by avramalex111 » Sun Jul 26, 2015 8:43 pm

The code doesn't work correctly...I discovered this on In stock products...I mean the first code from OpenTeam
opencartboost wrote:
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?
For category page, you need add code to file category.php and category.tpl.
You can try this guide.
1. Open file category.php (catalog/controller/product/category.php)
2. Find :

Code: Select all

$data['products'][] = array(]]></search>
3. Add after :

Code: Select all

'quantity'	=> $result['quantity'],
4. Open file category.tpl (catalog/view/theme/your_theme/template/product/category.tpl)
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>
6. Replace with:

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 } ?>
For home page. that is dependent your module, if you are using featured module, you need add code to file featured.php
(catalog/controller/module/featured.php) and featured.tpl (catalog/view/theme/your_theme/template/module/featured.tpl).

Newbie

Posts

Joined
Tue Jun 23, 2015 12:12 am

Post by opencartboost » Sun Jul 26, 2015 9:03 pm

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

Active Member

Posts

Joined
Thu Jul 09, 2015 5:59 am

Post by avramalex111 » Sun Jul 26, 2015 9:12 pm

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
hide_add_to_cart.xml

Newbie

Posts

Joined
Tue Jun 23, 2015 12:12 am

Post by opencartboost » Sun Jul 26, 2015 9:18 pm

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
hide_add_to_cart.xml
That mean code in file .tpl not same.
Find code add to cart button for your theme, and add conditional for product quantity > 0.

Active Member

Posts

Joined
Thu Jul 09, 2015 5:59 am

Post by Daan » Sat Jan 02, 2016 4:40 am

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??

Newbie

Posts

Joined
Wed Dec 30, 2015 10:25 pm

Post by ianhaney » Sun May 07, 2017 4:58 pm

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

Active Member

Posts

Joined
Sun Jun 24, 2012 2:30 am
Location - GB

Post by w1r3d » Mon Apr 09, 2018 6:16 pm

edited.

For fuatured, need to use 'quantity' => $product_info['quantity'],

Newbie

Posts

Joined
Wed Dec 06, 2017 3:39 pm

Post by jlbc » Wed Jul 10, 2019 9:20 am

ianhaney wrote:
Sun May 07, 2017 4:58 pm
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
Hi ianhaney. You can send me your code? I am try to do something similar

Newbie

Posts

Joined
Thu Feb 21, 2019 3:13 am
Who is online

Users browsing this forum: No registered users and 74 guests