shipping->reset_shipping(); $country = wc_clean( $_POST['calc_shipping_country'] ); $state = wc_clean( $_POST['calc_shipping_state'] ); $postcode = apply_filters( 'woocommerce_shipping_calculator_enable_postcode', true ) ? wc_clean( $_POST['calc_shipping_postcode'] ) : ''; $city = apply_filters( 'woocommerce_shipping_calculator_enable_city', false ) ? wc_clean( $_POST['calc_shipping_city'] ) : ''; if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce' ) ); } elseif ( $postcode ) { $postcode = wc_format_postcode( $postcode, $country ); } if ( $country ) { WC()->customer->set_location( $country, $state, $postcode, $city ); WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); } else { WC()->customer->set_to_base(); WC()->customer->set_shipping_to_base(); } WC()->customer->calculated_shipping( true ); wc_add_notice( __( 'Shipping costs updated.', 'woocommerce' ), 'notice' ); do_action( 'woocommerce_calculated_shipping' ); } catch ( Exception $e ) { if ( ! empty( $e ) ) wc_add_notice( $e, 'error' ); } } // Check cart items are valid do_action('woocommerce_check_cart_items'); // Calc totals WC()->cart->calculate_totals(); if ( sizeof( WC()->cart->get_cart() ) == 0 ) wc_get_template( 'cart/cart-empty.php' ); else wc_get_template( 'cart/cart.php' ); } }