There are several options.
- If you want to show out of stock but in latest positions you can combine your code snippet with lastest inventary order. You dont need code for this, in customizer theme usually you can change this option:
- If you want to hide out of stock and show in stock by latest. Then deleted your snippet, use same option that 1 and add this option too:
Woocommerce -> Products -> Inventary -> Hide out of stock products.
It is the best option for most stores, because it hides the products from the listings, but does not hide product page, and this does not affect seo or require additional work.
there’s also additional config to hide in serach results like explain here
Many things that a few years ago had to be done with code, Woocommrece brings that option added.
Or You can use this free plugin:
WooCommerce Sort By Stock
Regards
Related Posts:
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- How To Change The Html of Products filtration sidebar in Woocommerce?
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- Variation prices breakdown only for single product page
- How to add custom checkout field in user details mail template
- Remove Woocommerce product link
- Change the footer text on the login page
- How can I hook into and edit the text of a wp_nav_menu tag?
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to make an meta_query optional?
- Check if page parent has certain template
- How to Remove a Filter from the Admin List Table?
- Woocommerce, recognize the loop of related products
- Find variables available at a given hook
- Replace existing content from specific WooCommerce admin orders list column
- Getting my head round WordPress filter
- Woocommerce filter cart and category specific quantity [closed]
- How to set a custom path, for ajax image upload folder in admin?
- When using the_author hook, how can I determine the PHP file that generates each call to `the_author()`?
- How to call function at the bottom of post using plugin?
- How to add a second ‘place order’ button in WooCommerce [closed]
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- Handling Body class based on Template
- WooCommerce Related Products by Attribute
- Edit incorrect password message WordPress
- Show prices with tax in Woocommerce Mini Cart [closed]
- Reload part of checkout on changed shipping method
- Trying to build simple deposit code that hooks into woocommerce
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Add a product to checkout via form
- Remove a div from RSS feed
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- How to have different site identity logos on each page on Astra Theme [closed]
- Must filter functions receive all arguments passed to them?
- Filter wordpress posts without searching the keywords in the post content
- Display custom field value in woocommerce variable product via jQurey
- Adding custom field to product category and show it to shop/category shop page
- Remove span tags from WooCommerce Downloads page
- How to edit post meta data before publishing the post it self wordpress?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- using filter and hook inside class
- Discount in the specific product title using keyword ( Woocoommerce )
- How do I remove an action hook inside a class that is called by another class?
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- add_filter() inside another add_filter()
- How can i style “echo apply_filters”
- Add class to all meta boxes for a custom post type
- Clone the “proceed to cart” button and place it above checkout on the cart page, but only appear display size is 320px
- Woocommerce Price Text
- For each loop will not append to the_content hook
- Change Checkout “Place Order” text if cart has a specific product
- Send a custom notification to customer on WooCommerce cancelled order status
- Assign new post author IF another user in custom field on post transition
- Woocommerce – add tracking code to another email template
- Add text below WooCommerce short description if metabox value is true
- Is there a hook that I can use when a fatal error occurs?
- how to append ACF field data using one of the following filter/ hooks
- WooCommerce: Display product categories to make IF statement
- WordPress site with embedded menu – gives You don’t have permission to access /wp-content/themes/xxx/taxonomy-redirect.php on this server
- How to add aria role and schema markup to custom walker container
- Can I remove or edit an include() from a function with a filter?
- Dynamically adding filters
- Woocommerce custom Plugin in wordpress [closed]
- Add a custom class to the body tag using custom fields
- WooCommerce “Checkout Now” button [closed]
- Custom Taxonomy Select Menu: Setting default option value?
- Why doesn’t global $wp_query not get hooked?
- Creating customized php files in theme folder
- Dynamically Generate Functions and Hooks
- How to pass hook variable to function?
- WordPress doesn’t load HTML
- How to internationalize header image?
- How to separate product payment and shipping payment in WooCommerce checkout? [closed]
- apply_filters with several different values?
- How can I modify this code to make the search box include tags and meta
- How can i programmatically change the SKU of a product based on product variation?
- Execute PHP code only with specific user role
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- Add a custom WooCommerce settings tab with sections
- Display Sibling WooCommerce Product Categories on Archive Page
- Checking page before applying image restrictions while uploading
- Custom reduce stock code affecting date_modified – How to bypass?
- User filter posts by year
- manage_shop_order_posts_custom_column() hook is Not working In Functions.php file in my WordPress active theme
- Display custom product option in admin order details
- Woocommerce order status payment
- Dynamically added custom fields not displayed on WooCommerce email notifications
- Modify WooCommerce used to get all orders in dashboard
- Output product category link from WP_Query
- save_post trigerred twice
- Woocommerce. Get a list of products in the current category on the archive page and product page
- How to add a custom filter (by coding) before access one wordpress page ? And where to call the custom filter?
- How to work Woocommerce pagination inside shortcode?