UPDATED QUESTION AFTER Scriptonomy ANSWER BELOW
I have a woocommerce site in which I have a few different shipping options. I need to hide and show these shipping options based on the "Ship to different address button being checked"
//remove local pickup
function ddc_hide_shipping( $rates, $package ) {
unset( $rates['local_pickup'] );
return $rates;
}
//check if needs shipping address so we can unset local pickup
function ddc_update_shipping_options($instance) {
parse_str(html_entity_decode($instance), $postData);
if ( @$postData['ship_to_different_address'] ) {
add_filter('woocommerce_package_rates', 'ddc_hide_shipping');
}
}
add_action('woocommerce_checkout_update_order_review', 'ddc_update_shipping_options');
Using the above code that got from help from Scriptonomy I am getting closer. The problem I am having as this doesn't seem to work when the user checks and un checks the ship to different billing address. This only works for me on first page load, not on every ajax call to update the order review area.
Thank you.