Browse community

keep the sold out favourites visible, hide the rest

middleshelfPosted

specialty food, own site plus two retail counters in new south wales, about 2.5m a year. we hide sold out products from the shop by default, which is right most of the time. the exception is a short list of lines that sell out constantly but come back within a week or two, and those are the ones people actually search for. hide them and the phone rings off the hook.

so i want the global hide to stay on, with a handful of skus exempt and still showing the sold out badge. i've tried three functions.php snippets from chatgpt and claude. one did nothing, one showed every sold out product in the catalogue, one briefly took the shop page down. i'd like something that works.

18 replies

  1. nadia_94

    just manually set those ones to out of stock and put the rest on backorder

  2. middleshelfOP

    @nadia_94

    we've got 600-odd products. the whole point is not doing this by hand every time the supplier feed runs.

  3. nadia_94

    @middleshelf

    then tag the keepers and write a rule that only hides untagged sold out products. tag once, never touch it again.

  4. middleshelfOP

    @nadia_94

    tagging is fine. it's the rule i can't get right. four attempts, four different kinds of broken.

  5. nadia_94

    @nadia_94

    can you tag them by hand first? do that before any scripting. if their skus share a prefix nothing else uses, you can script the tagging later. one problem at a time.

  6. yusuf_36

    the meta_query example you'll find everywhere doesn't do this, just so you know. it says "stock status is out of stock OR sku is in the list", which returns every sold out product plus your favourites. the exact opposite of what you asked for.

    you need the list to override the hide, not to join the out of stock set. different shape entirely.

  7. felipe_sourcing

    easiest version is a filter on woocommerce_hide_out_of_stock_items, not a query rewrite. if the current page or product is on your allow list, return 'no' and the hide rule just doesn't apply there.

    so you're not changing which products come back, you're switching the global hide off for the pages you care about. less code, and it doesn't fight the theme.

  8. middleshelfOP

    @felipe_sourcing

    that's the direction i want. ours is the main shop page, not a category. does it still apply?

  9. felipe_sourcing

    @felipe_sourcing

    swap the is_product_category check for is_shop. i haven't tried it on a shop page with a builder grid, but that's the first change i'd make.

  10. w_tan

    if nothing works, it's usually the theme running its own query. what's on the shop page?

  11. middleshelfOP

    @w_tan

    a builder block grid, plus a filter sidebar. does that count as its own query?

  12. w_tan

    @w_tan

    almost certainly. which explains why the snippets did nothing. they were filtering a query that wasn't drawing the grid.

  13. marc_23

    "hide all except these" is backwards from how the setting is built, which is why every snippet fights you. the setting is global. you end up overriding it per page. fine, but be honest that that's what you're doing.

  14. chris_31

    how many products are we talking about? because if it's five, the plugin might genuinely be cheaper than the afternoon you're losing to this.

  15. middleshelfOP

    @chris_31

    it's seven. and i've now spent two afternoons. so yes, i'm aware.

  16. chris_31

    @chris_31

    seven. god. yeah, i'd have bought the plugin on day one.

  17. o_moore

    slight tangent but does the supplier feed overwrite your tags when it runs? ours wipes custom taxonomy on update and it took us a month to notice.

  18. middleshelfOP

    @o_moore

    oh no. i'm going to have to check that now, aren't i.

Have something useful to add?

Create a username and password in seconds, then reply.