I have a category gate for showing shipping on virtual products. Basically I have products I dont want to charge shipping on and I have them in a category called gifts... but I still want a shipping address. The problem is, is that when I use the category filter I built it wont save the address in the order... if i just use...
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true', 50 );
It works great...
But when i put the gate on it... it wont save the values... here is the gate...
//gifts filter
function HDM_gift_shipping() {
// set our flag to be false until we find a product in that category
$cat_check = false;
// check each cart item for our category
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
// if cat matches gift return true
if ( has_term( 'gift', 'product_cat', $product->id ) ) {
$cat_check = true;
// break because we only need one "true" to matter here
break;
}
}
// if a product in the cart is in our category, do something
if ( $cat_check ) {
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true', 50 );
}
}
add_action('woocommerce_before_checkout_billing_form', 'HDM_gift_shipping', 100);