Are you interested in leveraging BOGO discounts to attract more customers to your WooCommerce store with free sample product? Your search ends here! With the following snippet, you can effortlessly include a free sample product in your customers’ carts. Let’s discover how to seamlessly ‘Add free sample product in WooCommerce’!
Solution: Add a Free Sample Product With Every Purchase in WooCommerce
The below code snippet adds a button labeled “Order a Free Sample Product” to the product pages. This button allows customers to easily add a specific free product to their cart by clicking it.
add_action( 'woocommerce_single_product_summary', 'ts_add_free_sample_add_cart', 35 ); function ts_add_free_sample_add_cart() { ?> <form class="cart" method="post" enctype='multipart/form-data'> <button type="submit" name="add-to-cart" value="34" class="single_add_to_cart_button button alt" style="background-color: #FFBF43">Order a Free Product</button> <input type="hidden" name="free_sample" value="<?php the_ID(); ?>"> </form> <?php } add_filter( 'woocommerce_add_cart_item_data', 'ts_store_free_sample_id', 9999, 2 ); function ts_store_free_sample_id( $cart_item, $product_id ) { if ( isset( $_POST['free_sample'] ) ) { $cart_item['free_sample'] = $_POST['free_sample']; } return $cart_item; } add_filter( 'woocommerce_cart_item_name', 'ts_alter_cart_item_name', 9999, 3 ); function ts_alter_cart_item_name( $product_name, $cart_item, $cart_item_key ) { if ( 34 === $cart_item['product_id'] ) { $product = wc_get_product( $cart_item["free_sample"] ); } return $product_name; }
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
When a customer adds the product i.e. “Hoodie with Logo” to their cart on the single product page, they can also add a free sample product by clicking the button below.
Upon redirecting to the cart page, the customer will see two products: a Hoodie with a Logo and a free sample product – a Tshirt with Logo.
It also displays two products on the checkout page, i.e. Hoodie with Logo and a free sample product (Tshirt with Logo).
I hope this guide helped you set up a basic BOGO offer. If you’re looking to add products to your WooCommerce cart automatically based on conditions like cart total, category, or website visits, explore more advanced strategies that we have covered.