• Mr. W

    (@gabriel-winnberg)


    Hello,

    I’d like to have a front end checkbox that will simply flip on or off the back end option “Hide Out of Stock Items from the Catalog”.

    I’d like users to be able to browse the shop and at will, with one click, hide all products out of stock.

    I’ve tried different filter plugins such as WOOF – WooCommerce Products Filter (https://www.woocommerce-filter.com/), but one drawback is that it changes the view to a search result. So instead of displaying the category in question, it move to a new URL using a new template and lists all products in/out of stock. Plus that plugin has hundreds of features that I don’t use.

    Suggestions on how to make this happen?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I have been trying to solve this problem for a while myself. The simplest solution I have come up with is to Add an attribute to your products called Show. Give it two terms, In Stock only, and All Products. Then use the Woocommerce Layered Navigation widget to add links or a drop down with those options on your product collection page.

    After that if you want users settings remembered always checked you need to set a cookie or local storage up.

    Hope that helps.
    -T

    Thread Starter Mr. W

    (@gabriel-winnberg)

    Hi,

    Thanks for sharing!

    And how does that work? If you go to a category and select Stock only what happens exactly? Will it reload? Will it leave the category and list all products with attribute Stock only? I guess it’ll change the URL to the permalink base for attributes (not ideal for SEO)? Do you have a site where it’s implemented?

    Cheers,
    Gabriel

    It will add a query parameter to the end of the url it will look like this
    /?filtering=1&filter_show=589

    This won’t change your permalink structure, and won’t hurt your SEO. The only negative impact is if you have a ton of products it may take longer for your server to return the query from MySQL. I have 7000 products on my clients site so I have to make sure attributes are queried in sub categories.

    IE: mydomain.com/products/firearms/?filtering=1&filter_show=589
    vs
    mydomain.com/products/handguns/semi-auto-pistols/?filtering=1&filter_show=589

    I will implement it soon, you can email me personally for a link the site is still in testing so I don’t want to put it on blast just yet. Just add gmail to my name.

    Alright I tested my solution, and it works fine. The only change I would make is you only need to add the Term “In Stock Only” to the attribute Show. The the drop down or link will say:

    Show
    -Any
    -In Stock Only

    As for how it works basically when you use the Woocommerce layered widget, it basically adds a jQuery function to the page that when you select an option from the drop down it navigates the page to the same URL but adds a query parameter to the end of the URL:
    mydomain.com/products/firearms/?filtering=1&filter_show=589.

    This does not change your permalink structure at all, so your categories will remain intact. Google Bot just crawled my site last night, and it does not care about query params unless your site uses the original WordPress permalink structure.

    My advice try it if you don’t like it show in stock only, or use cookies and Javascript to solve the problem. There is no perfect solution for this, some people are afraid of cookies, showing in stock only may not inform customers of things they could back order, and my solution won’t remember there settings from category to category. I have tried all of the above and recommend this solution to minimize complexity. Merging this with the use of cookies is more complicated but best overall.

    Thread Starter Mr. W

    (@gabriel-winnberg)

    Hi,

    Thanks again, looks like an interesting solution.

    I also got a reply from plugin maker, they said they liked my idea and would implement it in the next release. I’ll keep you posted.

    And I’ll write you for your site.

    Cheers

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WooCommerce front end checkbox to toggle out of stock’ is closed to new replies.