Last active
August 15, 2019 16:40
-
-
Save wooexperte/3ce6aa157a24885cb6cbe78e45c84b2e to your computer and use it in GitHub Desktop.
WooCommerce - Produkt A beim Kauf von Produkt B automatisch im Warenkorb hinzufügen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 im Warenkorb hinzu. | |
if ( 54 == $product_id ) { | |
WC()->cart->add_to_cart( 56 ); | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
does that work with categories?
I tried to use the "$ product_id" code with "$ term_ids", but that does not work.
`
add_action( 'woocommerce_add_cart_item_data', function( $cart_item_data, $term_ids ) {
}, 10, 2 );`