Skip to content

Instantly share code, notes, and snippets.

@bernattorras
Created March 19, 2019 14:13
Show Gist options
  • Save bernattorras/39717d448bc767474670615919e5c41b to your computer and use it in GitHub Desktop.
Save bernattorras/39717d448bc767474670615919e5c41b to your computer and use it in GitHub Desktop.
<?php
// Check the "shipping to different address" checkbox on the Checkout page if the cart contains a gifted item
add_filter('woocommerce_ship_to_different_address_checked','check_shipping_if_gifting', 11, 1);
function check_shipping_if_gifting($val){
foreach ( WC()->cart->cart_contents as $key => $item ) {
if ( '' !== WCSG_Cart::get_recipient_from_cart_item( $item ) ) {
return true;
}
}
return $val;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment