Hide Add To Cart button when stock is 0 with version 3.90

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi,

I am trying to figure out how I can hide the Add To Cart button when the stock is 0, but it's not working.

Inventory method: Track inventory
Stock quantity: 0
Minimum stock qty: 0
Low stock activity: Disable buy button

The button is still visible but I get an Out of Stock error message when I press the button.

I think the button should not be visible when I can't purchase the product.
6 years ago
I agree..

But for now, maybe you can create an alternate CSS class for the buy button with
 display:none;

Then, in your _AddToCart.cshtml, in this section:
    @if (!Model.DisableBuyButton || !Model.DisableWishlistButton)
    {
        <div class="add-to-cart-panel">
            @Html.LabelFor(model => model.EnteredQuantity, new { @class = "qty-label" }, ":")
            @if (Model.AllowedQuantities.Count > 0)
            {
                @Html.DropDownListFor(model => model.EnteredQuantity, Model.AllowedQuantities, new {@class = "qty-dropdown"})
            }
            else
            {
                @Html.TextBoxFor(model => model.EnteredQuantity, new {@class = "qty-input"})
                
                //when a customer clicks 'Enter' button we submit the "add to cart" button (if visible)
                if (!Model.DisableBuyButton)
                {
                <script type="text/javascript">
                    $(document).ready(function() {
                        $("#@Html.FieldIdFor(model => model.EnteredQuantity)").keydown(function(event) {
                                 if (event.keyCode == 13) {
                                     $("#[email protected]").click();
                                     return false;
                                 }
                             });
                         });
                </script>
                 }
            }


You would create if/then/else condition to use the normal class on buy button if not disabled, and use your new hidden class if buy button is disabled.

Steve
6 years ago
patrick_sardinha wrote:
I am trying to figure out how I can hide the Add To Cart button when the stock is 0, but it's not working.

It is default nopCommerce design to hide buy button if Low stock activity you set to disable buy button.
To achieve this, you need to made small trick. If you set up stock = 0 it will not work.
Set stock quantity = 1, and made test order. Creating order (if remember correctly) call action which run method chosen in low stock activity.

Please test it first on fresh nopCommerce installation without any external themes/plugins.

Regards,
Tomasz
6 years ago
Hi,

Ok, let me test the options provided.

Thank you very much!
4 years ago
works the trick?
4 years ago
Hi
Go to, admin> configuration> all settings> producteditorsettings.disablebuybutton

noticeably false write True >  save

then look button appeared
admin> product page> disable buy button


regardless of quantity
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.