Zum Inhalt springen
Startseite » Woocommerce Snippets » Wenn „A“ kaufen, dann auch „B“

Wenn „A“ kaufen, dann auch „B“

Das folgende WooCommerce Snippet fügt automatisch beim Kauf von Produkt A das Produkt B im Warenkorb hinzu. Ideal z.B. für Komponenten Möbel, die zwingend ein bestimmtes Modul benötigen.
Der Kunde kann Produkt B auch wieder aus dem Warenkorb entfernen, wenn er das Modul schon besitzt.

Theme: Storefront

add_action( 'woocommerce_add_cart_item_data', function( $cart_item_data, $product_id ) {
// ID austauschen. Wenn Produkt A mit ID 54 im Warenkorb liegt, kommt Produkt B mit ID 56 automatisch dazu. 
	if ( 54 == $product_id ) {
		WC()->cart->add_to_cart( 56 );
	}
}, 10, 2 );