How to Setup Buy One Get One Free Without Plugin in WooCommerce?

The Buy One Get One Free permits make offers of the sort: on the off chance that the client adds to truck a particular amount of an item,
at that point add to truck at least one things of the equivalent (or another) product.

in the event that you add an product to cart with a particular SKU, you need another product naturally added to truck and a 100% coupon discount applied to it also.

add_filter( ‘woocommerce_add_to_cart_validation’, ‘wbcom_add_gift_if_sku_added_cart’, 10, 3 );

Add “product Gift” to WooCommerce Cart


function wbcom_add_gift_if_sku_added_cart( $passed, $product_id, $quantity ) {
global $woocommerce;

/* enter array of SKUs that give gift */
$skuswithgift = array(‘armpar’,’armsup’);

/* enter SKU of product gift */
$giftsku = ‘starter’;

/* enter name of coupon that gives 50% discount for specific product gift */
$coupon_code = ‘wbcom9Z’;

$product = wc_get_product( $product_id );

if ( $product->get_sku() && in_array( $product->get_sku(), $skuswithgift ) ) {
WC()->cart->add_to_cart( wc_get_product_id_by_sku($giftsku) );
wc_add_notice( __( ‘Hey, Supporter! As promised, I added #CustomizeWoo Video Lessons for Free – you will be able to access them in a single place (~ My Courses ~) and get premium support.’, ‘woocommerce’ ), ‘success’ );
$woocommerce->cart->add_discount( $coupon_code );
return $passed;


Leave a Reply

Your email address will not be published. Required fields are marked *