Utoljára aktív 1713290035

hide-0-stock-no-image.php Eredeti
1add_action('woocommerce_product_query', 'hide_products_without_image_and_zero_stock');
2
3function hide_products_without_image_and_zero_stock($q) {
4 $meta_query = $q->get('meta_query');
5
6 // Condition to check for products with an image
7 $meta_query[] = array(
8 'key' => '_thumbnail_id',
9 'compare' => 'EXISTS' // Ensures the product has an associated image
10 );
11
12 // Condition to check for products with stock quantity higher than 0
13 $meta_query[] = array(
14 'key' => '_stock',
15 'value' => 0,
16 'compare' => '>' // Ensures the product stock is greater than 0
17 );
18
19 // Set the modified meta query back on the query object
20 $q->set('meta_query', $meta_query);
21}
22