You can do that by adding the code below on your theme functions php file.
add_action( 'pre_get_posts', 'iconic_hide_out_of_stock_products' );
function iconic_hide_out_of_stock_products( $q ) {
if ( ! $q->is_main_query() || is_admin() ) {
return;
}
if ( $outofstock_term = get_term_by( 'name', 'outofstock', 'product_visibility' ) ) {
$tax_query = (array) $q->get('tax_query');
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => array( $outofstock_term->term_taxonomy_id ),
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
remove_action( 'pre_get_posts', 'iconic_hide_out_of_stock_products' );
}
This code was tested on the font end but it can easily be adapted to the back end
More info can be found here on this link https://iconicwp.com/hide-stock-products-woocommerce-catalog-pages/
Related Posts:
- Hidden woocommerce products still showing up in search results [closed]
- Pass custom Checkout field value to Stripe gateway in WooCommerce
- WooCommerce Shop Page Not Found 404
- How can I show an empty WooCommerce cart? [closed]
- Filter on a custom product attribute in WooCommerce using meta_query or tax_query [closed]
- Woocommerce : How to attach an custom attachment with customer-processing-order.php email template [closed]
- Woocommerce Pre Orders – Can i override templates?
- Woocommerce checkout via external page [closed]
- Does the woocommerce_order_status_changed hook fire when WooCommerce updates an order status automatically? [closed]
- Programmatically adding product attributes to WP / Woo commerce
- Display File Types For Woocommerce Downloadable Products On Product Page
- Apply Additional Discount after coupon
- Is it possible to add a sidebar to Storefront’s Welcome page
- Programmatically setting Woocommerce product price
- Woocommerce reviews xss issue [closed]
- Register a new user on wooCommerce using Rest API
- Woocommerce REST API allow normal users make an order
- WooComerce shows blank site (Shop)
- How to update custom field in WooCommerce
- Add product categories to receipt
- Woocommerce specific product template for product type
- How can I use a gravity form to send an e-card?
- How to select default Woocommerce category page
- Creating Product Table using Gutenberg
- I can ‘t display product images based on the label
- SKU for each product on every page
- Timber, Twig, and Woocommerce: Last product stays in the cart after checkout
- Woocommerce Cart Default Language Not Changing
- Make this Fast and Queryable
- WooCommerce slider filter for numerical attributes
- Adding product info for printing to custom Woocommerce Product Display tab [closed]
- WooCommerce Cart Link based on Cookie Values
- Woocommerce is_shop not on page slug? [closed]
- WooCommerce – Trigger Checkout Form Validation
- Debugging why featured images have stopped showing in WooCommerce on the homepage [closed]
- WooCommerce minimum order amount for specific country excluding local pickup [closed]
- Add shipping address to Woocommerce order emails [closed]
- woocommerce list product by id
- Woocommerce Login Redirect to old domain
- add sub subpage endpoint to woocommerce plugin my-account section
- Show Content On below single product with specific category
- How to change a WooCommerce Subscription Deposit and Monthly Payment? [closed]
- how to change the “return to shop” button text? [closed]
- how to scrolling image on single product page
- How to display WooCommerce product tag names on home and category pages
- Specifically Link To the “Leave a review” part of product page? [closed]
- Problem while adding the variable product woocommerce
- Woocommerce pre_get_posts query variation meta data not working
- Can’t hide product attributes with css on WooCommerce Product Page
- Updating product image
- Split in 2 columns add to cart button and variable forms
- Images not uploading on product page of woocommercr
- How to access WC()->cart in CF7 hook wpcf7_special_mail_tags
- Woocomerce Edit source code of form in wordpress
- Single Product Page as a Popup
- Woocommerce to get restaurant table numbers in the checkout fields from the url
- UX Builder not loading for product description edits
- I need help with storefront theme shop page
- Jump to Footer On Scroll – Woocommerce Pages Phones Only
- WordPress Development Workflow
- Woocommerce redirection product_name -> product_cat/product_name
- Woocommerce shop page not showing all products
- Wrong Billing Information in WC_Checkout->get_checkout_fields(‘billing’)?
- How to display two different custom taxonomy terms on a WooCommerce single product page
- Registration roles
- why my price is not showing while adding new product?
- How to send Woocommerce Customer Details (Name, Email and Phone Number) to Admin upon signup
- Sending billing details via POST request to an API
- Remove username and account password field from checkout page
- How to send an invoice with details to the customers
- Tax exclusive if coupon applied else tax inclusive in items
- WooCommerce Registration, Sync User, Billing and Shipping info
- How to change “add to basket” button text in WooCommerce based on product category?
- Select all product woocommerce
- Woocommerce REST API: creating variations
- How to customize product at cart page
- WooCommerce Storefront site-header padding
- How to check which shortcode is using my template?
- woocommerce: when adding or removing items to cart , it takes cart a few seconds to read changes?
- How to get woocommerce integration instance?
- When to use a child theme for WooCommerce Storefront?
- WooCommerce: Bulk Quantity in Cart
- Remove Span Class From Woocommerce Price
- Woocommerce shows empty columns [closed]
- Product atributes in title of order (not in description)
- How to create custome pdf file of my invioice in wordpress
- How to get sub items of parent menu item?
- WordPress and WooCommerce How to Assign Attribute Based Pricing
- Notice: Trying to get property of non-object in bodycenter [closed]
- WooCommerce remove billing detail completly
- unable to get product by category only getting product added lastly
- Storefront Child Theme show product attribute [closed]
- Can I remove WooCommerce specific product categories from shop managers?
- Fetch products with filter by similar categories at same time
- Trying query woocommerce product order by menu order and stock status
- editing product page template – getting template for related products not working
- Woocommerce | I want to the button ‘Add to Cart’ on the (all) product-page changed by just ‘open product’ button
- Adding line breaks in WooCommerce order processing emails
- Disable Woocommerce Block Editor
- Woocommerce backend sorting product drag drop by menu_order to date