Skip to content

Instantly share code, notes, and snippets.

@flabernardez
Created August 18, 2021 17:29
Show Gist options
  • Save flabernardez/dbea5514044ac7aa669c9c13e51d84d5 to your computer and use it in GitHub Desktop.
Save flabernardez/dbea5514044ac7aa669c9c13e51d84d5 to your computer and use it in GitHub Desktop.
#woocommerce añadir producto al carrito cuando se añade otro
<?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 );