Disable WooCommerce Out Of Stock

0.0/5
<?php
add_filter( 'woocommerce_product_query_meta_query', 'shop_only_instock_products', 10, 2 );
function shop_only_instock_products( $meta_query, $query ) {
// Only on shop archive pages
if( is_admin() || is_search() || ! is_shop() ) return $meta_query;

$meta_query[] = array(
	'key' => '_stock_status',
	'value' => 'outofstock',
	'compare' => '!='
);
	return $meta_query;
}

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

Disables product that are out of stock in the catalog for users without the administrator’s permission.

Author

Tags