Jump to content
Latest News: (loading..)
puggybelle

Hide Add To Cart, Buy and Buy Now for out of stock items

Recommended Posts

I have Add To Cart appearing on products that are out of stock in product_info

I have Buy appearing on products out of stock in the New Products module

I have Buy Now appearing when viewing all products in a category via index.php

Lots of ways to do this if using an older version of osCommerce, but I can find nothing about the newest release, the responsive one.

I'm using 2.3.4.1 CE

How to do this?  How to stop these 'buttons' from appearing if an item has a quantity of zero?

I don't want customers adding an item to their cart just to be told it's out-of-stock and please remove from your cart.  It looks bad.

- Andrea

 

Share this post


Link to post
Share on other sites

You need a header tags module to disable the buttons if they have the data attribute set for out of stock. It's discussed here:

 


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce here: https://github.com/gburton/osCommerce-234-bootstrap/archive/master.zip

 

For Github users: Bootstrap addons - one per branch - https://github.com/BrockleyJohn/Responsive-osCommerce/wiki/Overview-of-Branches

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Share this post


Link to post
Share on other sites

If I Google "remove add to cart button oscommerce" I should find something current, right? 

Not so much! 

Whatever happened to the good old days of ask a question and get some help?   

The forum is loaded with code-junkies now, not real people with online stores that actually use this software.  Not anymore.

First guy gives me a link to a thread that is 93-pages long and four years old. 

Second guy says...Burt can help....and I'm sitting here like...who the hell is Burt?

Share this post


Link to post
Share on other sites
Posted (edited)
Quote

If I Google "remove add to cart button oscommerce" I should find something current, right?

That has not much to do with this forum, wouldn't you agree? We cannot take any sort of influence on Google's search results.

 

Quote

Whatever happened to the good old days of ask a question and get some help? 

I think you have been provided with help here and in the other thread (advanced specials). Unless for you getting help means having everything served on a silver platter for free.

 

Quote

The forum is loaded with code-junkies now, not real people with online stores that actually use this software.

True. Not so many shop owners left anymore since osC doesn't evolve as fast as other cart systems these days. Still those who are left are not code-junkies. They are store owners that try to help osC move somewhat forward in any way they can in their free time.
 

Quote

First guy gives me a link to a thread that is 93-pages long and four years old.

The first guy, his name is John btw, has provided you with a link to the answer you seek. You just need to know which link to click. Just try and click on the bold text BrockleyJohn replied to a topic

The other guy, also named John, mentioned Burt by name because we all know who Burt is or at least those that use his Community Edition which would include you too.
He is a osC Team member so just click on the "Staff" tab at the top and you should see a "monkey with a hat" avatar guy, that's him.

Just a friendly advice. I know things can get frustrating if you try to get something working as quick as possible but bear in mind there are people here from all around the globe so there is a time difference to consider and consider that those people are trying to help here for free most of the time. So keep your attitude in check please and don't try to vent it out here in the forum.

Edited by Tsimi

When you ask for help/support:

  • Always state your osCommerce version
  • If possible, list up installed add-ons
  • 3rd party templates are not supported in the forum

Latest osC: osCommerce CE (Community Edition aka. v2.3.4.1 Frozen)

 

Share this post


Link to post
Share on other sites
6 hours ago, puggybelle said:

Whatever happened to the good old days of ask a question and get some help?   

The trolls ate them


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce here: https://github.com/gburton/osCommerce-234-bootstrap/archive/master.zip

 

For Github users: Bootstrap addons - one per branch - https://github.com/BrockleyJohn/Responsive-osCommerce/wiki/Overview-of-Branches

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Share this post


Link to post
Share on other sites
10 hours ago, BrockleyJohn said:

The trolls ate them

I hope you're not referring to me somehow with that.  I've seen quite a bit of infighting with the developers up here, too.  My point was that there seems to be more of them than shopowners anymore. 

15 hours ago, Tsimi said:

Just a friendly advice. I know things can get frustrating if you try to get something working as quick as possible but bear in mind there are people here from all around the globe so there is a time difference to consider and consider that those people are trying to help here for free most of the time. So keep your attitude in check please and don't try to vent it out here in the forum.

I sincerely apologize.  You're right, I am frustrated.  This is not my old-school osCommerce anymore!  The learning curve is more than I expected, given that I've been running a heavily modded 2.2 site for over a decade.  I started rebuilding my site on 2.3.4.1 CE a week ago and really hoped to go live with it by tomorrow.  I'm not even 50% there.  So...my attitude was in the dumper last night, I guess.  I'm truly sorry if I offended anyone.

Stephan - I tried that out-of-stock ribbon contrib yesterday.  I was able to get it working on all products listed when clicking on a category, but nowhere else.  And I don't care for how it looks.  The ribbon is appearing in the top right corner which looks kind of funky with the Buy Now button in the product listing above it knocking heads.  I think I'll be un-doing that this afternoon. 

And it's back to square one with buttons.

Share this post


Link to post
Share on other sites
Posted (edited)

@puggybelle

I too want to do everything myself. Maybe it's the control freak in me. Maybe it's because I'm cheap. Whatever.

Sometimes, though, the best solution is to hire someone to 'help' you build your site for your. Time is money, as they say. How long will it take to get your site up when, every time you run into a snag, you have to ask for a volunteer to help (all of us on here are volunteers. None of us get paid for this)?

Help some of the developers here feed their families too. The sooner you get your site up and running, the better.

M

PS: I am not a developer, and can't/won't do your site for you. So no, I wasn't fishing for work.

Edited by ArtcoInc

If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release here

Share this post


Link to post
Share on other sites

Then please enlighten me, oh wise one ...


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release here

Share this post


Link to post
Share on other sites

@puggybelle

There are 2 ways of doing what you want. 

1. Hard code it into every file that contains a buy button

2. Do it the way the first John showed in his example, creating a header_tags module and therefore you don't need to go change code in various files.

The way to hard code it should not be much different than it was in the past.

You basically check if the product has a quantity of 1 or more then show buy button else remove/deactivate button and show out of stock notification.

I know redirecting you to another thread might not give you the answer right away but it will help you understand more of the code and its function.

Here a thread with the same request as yours.

https://forums.oscommerce.com/topic/408605-show-out-of-stock-button-in-place-of-buy-now-when-stock-is-less-than-1/#comment-1735993

Scroll down and read around Burts aswers.

If you still should have a hard time getting it implemented report back and we see what we can do.

 


When you ask for help/support:

  • Always state your osCommerce version
  • If possible, list up installed add-ons
  • 3rd party templates are not supported in the forum

Latest osC: osCommerce CE (Community Edition aka. v2.3.4.1 Frozen)

 

Share this post


Link to post
Share on other sites

@puggybelle

As @Tsimi mentioned, you can make edits to the core code to hide the 'Buy' or 'Add to Cart' buttons. You need to do this everywhere these buttons display. At a minimum, these includes /includes/modules/product_listing.php and /product_info.php. You may also need to look at /includes/modules/new_products.php and /specials.php.

While I have done this on my older shops, the current coding preference is to avoid core changes. As @Tsimi also said, you might be able to write a header_tag that does this for you, without any core changes. I know that @burt wrote one that disabled the Checkout button in the shopping cart if there were insufficient quantities of all the products in the cart. Probably a similar one could be written to disable the 'Buy' or 'Add to Cart' buttons too.

While replacing the 'Buy' or 'Add to Cart' buttons with an 'Out of Stock' non-clickable button may be all you need, you may also want to consider displaying how many pieces are in stock.

@wHiTeHaT I'm still confused. Please enlighten me.

M


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release here

Share this post


Link to post
Share on other sites

At this point, I'd prefer to hard code any changes in my files.  Just don't know how.  I believe I know what files need to be edited,  just unsure how to do it.

I've done this in my 2.2 site, but the files there don't even resemble what I'm dealing with now.

Looked at the response from Burt and his recommendation on how to change the tep_draw_button code in product_info.php  I thought, okay, easy enough.

Only problem is...my product_info.php file makes no mention whatsoever of a button!  Exactly where IS that button code at?  The button that appears when viewing a product.  ???  Seems like everything is where I would least expect it now with the newest release.

It's frustrating only being able to find info on editing older versions of osCommerce.  Apparently, that thread Burt was in was for something other than 2.3.4.1 CE so I'm stuck.  Again.

 

Share this post


Link to post
Share on other sites
Posted (edited)

@puggybelle

(since you are ok with core changes ...)

I've not done this with the latest 2.3.4.1CE version, but here's a place to start ...

Look in /includes/modules/content/product_info/templates/tpl_cm_pi_buy_button.php. That's the code to display the 'Buy' or 'Add to Cart' button.

Try wrapping that in an IF statement .... something like:

if($product_info['products_quantity'] > 0) {

and close it with:

}

Try that first.

If that works, and if you want to display a 'Out of Stock' notice, replace the closing } with an else statement

} else {
  <your code to display the 'Out of Stock' notice>
}

Like I said, totally untested. But, this should point you in the right direction. Mind you, this is just for the product_info page. You'd still have to make the same change(s) everywhere else that the 'Buy' or 'Add to Cart' buttons are displayed.

HTH

Malcolm

Edited by ArtcoInc

If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release here

Share this post


Link to post
Share on other sites

I don't know where to put that code.  I've tried it in a few places in the file and no results.  Nothing breaks, but...the button doesn't disappear when viewing an Out Of Stock product.

Ideally, I'd like to replace the Add To Cart buttons with a static Out Of Stock button which I've already put in languages/english.php called IMAGE_BUTTON_DISABLE Onscreen the button reads Out Of Stock and is not clickable

Ripping off Burt now...:smile:

Share this post


Link to post
Share on other sites

@puggybelle

This is what I was talking about before. Just a quick-and-dirty effort. Give this a try ...

in /includes/modules/content/product_info/templates/tpl_cm_pi_buy_button.php

1) Make a backup copy of this file somewhere safe

2) Replace the entire code within it with this:

 

<div class="col-xs-<?php echo $content_width; ?> text-right cm-pi-buy-button">
<?php
  if($product_info['products_quantity'] >0) {
    echo tep_draw_button(MODULE_CONTENT_PI_BUY_BUTTON_TEXT, 'fa fa-shopping-cart', null, 'primary', array('params' => 'data-has-attributes="' . (($products_attributes['total'] > 0) ? '1' : '0') . '" data-in-stock="' . (int)$product_info['products_quantity'] . '" data-product-id="' . (int)$product_info['products_id'] . '"'), 'btn-success btn-product-info btn-buy');
    echo tep_draw_hidden_field('products_id', (int)$product_info['products_id']);
  } else {
    echo tep_draw_button(IMAGE_BUTTON_DISABLE, '', null, '', '', 'btn-danger disabled');
  }
?>
</div>

Notes:

1) This assumes that you defined IMAGE_BUTTON_DISABLE somewhere (as you said you did)

2) This disables the button on the Product_Info page ONLY. You'd have to do something like this for EVERY other page that has a 'Buy' or 'Add to Cart' button.

3) Even though the 'Out Of Stock' button is 'disabled', if you click on it, it still takes you to the Shopping Cart. But, like I said, this is a quick-and-dirty first attempt.

Hopefully, this will get you pointed in the right direction ...

M


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release here

Share this post


Link to post
Share on other sites

I was close! :biggrin:

Yes, that adds my Out Of Stock button to product_info.  When clicked, I go to the shopping cart, as you said.

But hey!  That is PROGRESS!  Thanks!

Now...how to make it a static button?  I'm seeing some things in Google regarding making a button "fixed" in CSS.  Think this is something I could add to user.css to disable this button from being clickable?  Or am I in the wrong part of town again...

 

Share this post


Link to post
Share on other sites

@puggybelle

Try this ...

In the code I gave you before, find:

    echo tep_draw_button(IMAGE_BUTTON_DISABLE, '', null, '', '', 'btn-danger disabled');

and replace with this:

    echo tep_draw_button(IMAGE_BUTTON_DISABLE, '', '#' , '', '', 'btn-danger disabled');

I think that CSS would turn out to be more of a headache than a relief.

M

 


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release here

Share this post


Link to post
Share on other sites

Yep, I've found myself a genius in the forum.  That's perfect!  Static button - no clicking.  Just perfect!

I have to ask you...regarding the other files I need to edit.  Does product_listing have some button code hidden in a template, too?  New Products?  Specials?

Thank You so much! 

Share this post


Link to post
Share on other sites

1) If someone helps you, it's polite to 'like' their posts :cool:

2) Take this opportunity to learn how to work these things out yourself ... you don't expect me to do everything for you, do you? :tongue:

M


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release here

Share this post


Link to post
Share on other sites

Geez, I called you a genius, you know? 

I think I just liked your previous post.  Honestly, I have never run my mouse over that heart-shaped button before.  Sorry!

And no...I don't expect you to fix it all for me. 

But, don't be surprised if you see me again whining about how I can't get the next one to work.  Hopefully not!

Thank You very much for all of your help today, I do appreciate it.

Share this post


Link to post
Share on other sites

@puggybelle

Here's a couple of hints ...

/specials.php calls /includes/modules/product_listing.php . So, there's nothing to change in /specials.php

/products_new.php also calls /includes/modules/product_listing.php. Again, nothing to change here.

Both /includes/modules/new_products.php  (which is not the same as /products_new.php) and /includes/modules/product_listing.php do not have any templates. You will have to edit these two core files themselves. It's going to be a bit more difficult, though. Check it out, you'll see.

As I recall, template files are not considered 'core files'. They are there to control how something is displayed. The whole reason for them is so you can edit them to make your store look the way you want without touching the core code.

Good luck :smile:

M


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release here

Share this post


Link to post
Share on other sites

@puggybelle

Yeah, the new osC is more modular now meaning the main file contents has been reduced to a few lines of codes to call the so called content modules to build the page.
Like for example the product_info.php file, the whole contents has been split into multiple modules which put together build the product info page.
The advantage of such an approach is you can change most things without touching the core code of osC which hopefully will make updates in the future a bit easier.

Here my approach for the product info and product listing page. And as Malcolm already mentioned the product listing file takes care of specials and what's new as well.

english.php

ADD

define('IMAGE_BUTTON_SOLD_OUT', 'Sold Out');

tpl_cm_pi_buy_button.php (backup file first!)

Replace the whole code with this

<div class="col-xs-<?php echo $content_width; ?> text-right cm-pi-buy-button">
  <?php
 if ($product_info['products_quantity'] >= 1) {   
  echo tep_draw_button(MODULE_CONTENT_PI_BUY_BUTTON_TEXT, 'fa fa-shopping-cart', null, 'primary', array('params' => 'data-has-attributes="' . (($products_attributes['total'] > 0) ? '1' : '0') . '" data-in-stock="' . (int)$product_info['products_quantity'] . '" data-product-id="' . (int)$product_info['products_id'] . '"'), 'btn-success btn-product-info btn-buy');
  echo tep_draw_hidden_field('products_id', (int)$product_info['products_id']);
 } else {
  echo tep_draw_button(IMAGE_BUTTON_SOLD_OUT, 'fas fa-ban', null, 'primary', array('params' => 'disabled="disabled"'), 'btn-danger');
 }  
  ?>
</div>

product_listing.php (takes care of specials and what's new too)

FIND

      if (PRODUCT_LIST_BUY_NOW > 0) {
        $prod_list_contents .= '       <div class="col-xs-6 text-right">';
        $prod_list_contents .=           tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'fa fa-shopping-cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . (int)$listing['products_id']), NULL, array('params' => 'data-has-attributes="' . ((tep_has_product_attributes((int)$listing['products_id']) === true) ? '1' : '0') . '" data-in-stock="' . (int)$listing['in_stock'] . '" data-product-id="' . (int)$listing['products_id'] . '"'), 'btn-success btn-product-listing btn-buy');
        $prod_list_contents .= '       </div>';
      }

REPLACE WITH

      if (PRODUCT_LIST_BUY_NOW > 0) {
        $prod_list_contents .= '       <div class="col-xs-6 text-right">';
            if ( tep_get_products_stock($listing['products_id']) >= 1) {
                $prod_list_contents .=           tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'fa fa-shopping-cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . (int)$listing['products_id']), NULL, array('params' => 'data-has-attributes="' . ((tep_has_product_attributes((int)$listing['products_id']) === true) ? '1' : '0') . '" data-in-stock="' . (int)$listing['in_stock'] . '" data-product-id="' . (int)$listing['products_id'] . '"'), 'btn-success btn-product-listing btn-buy');
            } else {
                $prod_list_contents .=    tep_draw_button(IMAGE_BUTTON_SOLD_OUT, 'fas fa-ban', null, 'primary', array('params' => 'disabled="disabled"'), 'btn-danger');
            }
        $prod_list_contents .= '       </div>';
      }

In both cases we do a simple check. If products quantity is higher or equal to 1 then show normal buy button else show sold out button.

Now what you can try is to do the new products modules inside the index (tpl_cm_i_new_products.php) and index_nested (tpl_cm_in_new_products.php) modules.
    

 


When you ask for help/support:

  • Always state your osCommerce version
  • If possible, list up installed add-ons
  • 3rd party templates are not supported in the forum

Latest osC: osCommerce CE (Community Edition aka. v2.3.4.1 Frozen)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×