Notice: Array to string conversion in /kunden/284747_51491/webseiten/works/essential-grid/wp-includes/formatting.php on line 1098

Notice: Array to string conversion in /kunden/284747_51491/webseiten/works/essential-grid/wp-includes/formatting.php on line 1098

Notice: Array to string conversion in /kunden/284747_51491/webseiten/works/essential-grid/wp-includes/formatting.php on line 1098

Notice: Array to string conversion in /kunden/284747_51491/webseiten/works/essential-grid/wp-includes/formatting.php on line 1098
Only Include In-Stock WooCommerce Products in Grid - Essential Grid WordPress Gallery Plugin

Only Include In-Stock WooCommerce Products in Grid

The following code can be used to modify the grid’s items to only include products listed as “In Stock”. Only Applicable for WooCommerce Product Grids.

Step 1:

Get your grid’s ID.

Step 2:

Add the following code to your theme’s “functions.php” file, modifying the number “1” with your grid’s ID.

add_filter('essgrid_modify_posts', 'eg_mod_posts', 10, 2);
 
function eg_mod_posts($posts, $grid_id) {
 
    // only process if Grid ID equals "1"
    if($grid_id == 1) {
 
        $products = array();
 
        foreach($posts as $post) {
 
            $id = $post['ID'];
            $meta = get_metadata('post', $id);
 
            if($meta['_stock_status'][0] == 'instock') {
 
                $products[] = $post;
 
            }
 
        }
 
        return $products;
 
    }
 
    return $posts;
 
} 
Only Include In-Stock WooCommerce Products in Grid

The Author

KC

Strength does not come from winning. Your struggles develop your strengths. When you go through hardships and decide not to surrender, that is strength.

Liked this Post?
Please Share it!