shipping()->reset_shipping(); $address = array(); $address['country'] = isset( $_POST['calc_shipping_country'] ) ? kkart_clean( wp_unslash( $_POST['calc_shipping_country'] ) ) : ''; // WPCS: input var ok, CSRF ok, sanitization ok. $address['state'] = isset( $_POST['calc_shipping_state'] ) ? kkart_clean( wp_unslash( $_POST['calc_shipping_state'] ) ) : ''; // WPCS: input var ok, CSRF ok, sanitization ok. $address['postcode'] = isset( $_POST['calc_shipping_postcode'] ) ? kkart_clean( wp_unslash( $_POST['calc_shipping_postcode'] ) ) : ''; // WPCS: input var ok, CSRF ok, sanitization ok. $address['city'] = isset( $_POST['calc_shipping_city'] ) ? kkart_clean( wp_unslash( $_POST['calc_shipping_city'] ) ) : ''; // WPCS: input var ok, CSRF ok, sanitization ok. $address = apply_filters( 'kkart_cart_calculate_shipping_address', $address ); if ( $address['postcode'] && ! KKART_Validation::is_postcode( $address['postcode'], $address['country'] ) ) { throw new Exception( __( 'Please enter a valid postcode / ZIP.', 'kkart' ) ); } elseif ( $address['postcode'] ) { $address['postcode'] = kkart_format_postcode( $address['postcode'], $address['country'] ); } if ( $address['country'] ) { if ( ! KKART()->customer->get_billing_first_name() ) { KKART()->customer->set_billing_location( $address['country'], $address['state'], $address['postcode'], $address['city'] ); } KKART()->customer->set_shipping_location( $address['country'], $address['state'], $address['postcode'], $address['city'] ); } else { KKART()->customer->set_billing_address_to_base(); KKART()->customer->set_shipping_address_to_base(); } KKART()->customer->set_calculated_shipping( true ); KKART()->customer->save(); kkart_add_notice( __( 'Shipping costs updated.', 'kkart' ), 'notice' ); do_action( 'kkart_calculated_shipping' ); } catch ( Exception $e ) { if ( ! empty( $e ) ) { kkart_add_notice( $e->getMessage(), 'error' ); } } } /** * Output the cart shortcode. * * @param array $atts Shortcode attributes. */ public static function output( $atts ) { if ( ! apply_filters( 'kkart_output_cart_shortcode_content', true ) ) { return; } // Constants. kkart_maybe_define_constant( 'KKART_CART', true ); $atts = shortcode_atts( array(), $atts, 'kkart_cart' ); $nonce_value = kkart_get_var( $_REQUEST['kkart-shipping-calculator-nonce'], kkart_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine. // Update Shipping. Nonce check uses new value and old value (kkart-cart). @todo remove in 4.0. if ( ! empty( $_POST['calc_shipping'] ) && ( wp_verify_nonce( $nonce_value, 'kkart-shipping-calculator' ) || wp_verify_nonce( $nonce_value, 'kkart-cart' ) ) ) { // WPCS: input var ok. self::calculate_shipping(); // Also calc totals before we check items so subtotals etc are up to date. KKART()->cart->calculate_totals(); } // Check cart items are valid. do_action( 'kkart_check_cart_items' ); // Calc totals. KKART()->cart->calculate_totals(); if ( KKART()->cart->is_empty() ) {do_action( 'kkart_cart_is_empty' ); if ( kkart_get_page_id( 'shop' ) > 0 ) : ?>