Add Product B to WooCommerce Cart When Adding Product A
If you want a specific product to be added to your cart automatically when another product is added you can do this with a little code in your child theme by hooking into the 'woocommerce_add_cart_item_data' hook and checking for the current item being added and then using the WooCommerce add_to_cart function to add additional items to the cart.
add_action( 'woocommerce_add_cart_item_data', function( $cart_item_data, $product_id ) {
// If added product ID is 67 then also add product with an ID of 15
if ( 67 == $product_id ) {
WC()->cart->add_to_cart( 15 );
}
}, 10, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin (we recommend Code Snippets)