Malin gist felülvizsgálása . Revízióhoz ugrás
1 file changed, 21 insertions
hide-0-stock-no-image.php(fájl létrehozva)
@@ -0,0 +1,21 @@ | |||
1 | + | add_action('woocommerce_product_query', 'hide_products_without_image_and_zero_stock'); | |
2 | + | ||
3 | + | function 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 | + | } |
Újabb
Régebbi