Created
August 18, 2021 17:29
-
-
Save flabernardez/dbea5514044ac7aa669c9c13e51d84d5 to your computer and use it in GitHub Desktop.
#woocommerce añadir producto al carrito cuando se añade otro
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
<?php | |
add_action( 'woocommerce_add_cart_item_data', function( $cart_item_data, $product_id ) { | |
// If added product ID is 8397 then also add product with an ID of 8452 | |
if ( 8397 == $product_id ) { | |
WC()->cart->add_to_cart( 8452 ); | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from https://wpexplorer-themes.com/total/snippets/add-product-b-to-woocommerce-cart-when-adding-product-a/#:~:text=If%20you%20want%20a%20specific,WooCommerce%20add_to_cart%20function%20to%20add