To manage your WooCommerce product stock levels more effectively, implementing a BOGO (Buy One Get One) offer based on product stock count could be the perfect solution. For example, you can use BOGO deals for products that aren’t selling as quickly as you’d like or for items with low stock to help clear out inventory and make space for new stock. Let’s see how it works!
Solution: Add BOGO (Buy One Get One) offer based on Product Stock Count in WooCommerce
The following code checks whether the stock quantity of products in the cart is greater than a predefined threshold (e.g. minimum 5). When this condition is met, the free product is added to the cart.
add_action('woocommerce_before_calculate_totals', 'ts_free_product_based_on_stock', 10, 1); function ts_free_product_based_on_stock($cart) { if (is_admin() && !defined('DOING_AJAX')) return; // Define the product ID of the free product $free_product_id = 470; // Replace with your actual free product ID $minimum_stock_quantity = 5; // Set the minimum stock quantity to offer the free product // Check if the free product is already in the cart $free_product_in_cart = false; foreach ($cart->get_cart() as $cart_item) { if ($cart_item['product_id'] == $free_product_id) { $free_product_in_cart = true; break; } } // Check if any product in the cart has a stock quantity that allows offering the free product foreach ($cart->get_cart() as $cart_item) { $product = wc_get_product($cart_item['product_id']); $stock_quantity = $product->get_stock_quantity(); if (!$free_product_in_cart && $stock_quantity >= $minimum_stock_quantity) { // Add the free product to the cart $cart->add_to_cart($free_product_id); break; // Stop checking once we add the free product } } }
This to the shop owners who are running or planning to run BOGO offers on their WooCommerce store…
BOGO deals are great for increasing your sales, but have you thought about which offers are bringing you more revenue and which offers are not performing that great?
Don’t just set a BOGO deal, track the revenue generated by your deals in real-time with the Flexi BOGO for WooCommerce plugin.
Output
Let’s imagine that a customer has added an Android SmartPhone to the cart. Have a look at the stock quantity of this item present in the cart from the backend as shown in this image.
As the product’s stock quantity is greater than the predefined minimum stock quantity threshold, the free product gets added to the cart.
Let’s imagine that the stock quantity of the above product falls below 5, in such cases the free product is not added to the cart.
Another easy want to move stock quickly is by providing bulk discount tiers. This customization of WooCommerce bulk quantity-tiered discounts is set to apply the discount based on the total quantity of the items present in the cart, making it an effective strategy to encourage customers to buy more..