diff --git a/woocommerce-gateway-billmate/class-billmate-checkout.php b/woocommerce-gateway-billmate/class-billmate-checkout.php index 7a7647db..4ad89dfe 100644 --- a/woocommerce-gateway-billmate/class-billmate-checkout.php +++ b/woocommerce-gateway-billmate/class-billmate-checkout.php @@ -503,18 +503,28 @@ function billmate_update_address(){ $order->set_address($shipping_address, 'shipping'); } } - WC()->customer->set_billing_country( $billing_address['country'] ); WC()->customer->set_shipping_country( $shipping_address['country'] ); WC()->customer->set_billing_postcode( $billing_address['postcode'] ); WC()->customer->set_shipping_postcode( $shipping_address['postcode'] ); + WC()->customer->set_billing_city( $billing_address['city'] ); + WC()->customer->set_shipping_city( $shipping_address['city'] ); + WC()->customer->set_billing_address_1( $billing_address['address_1'] ); + WC()->customer->set_shipping_address_1( $shipping_address['address_1'] ); + WC()->customer->set_billing_address( $billing_address['address_1'] ); + WC()->customer->set_shipping_address( $shipping_address['address_1'] ); WC()->customer->save(); - + $chosen_shipping = WC()->session->get('billmate_checkout_saved_shipping_method'); + WC()->shipping->reset_shipping(); + WC()->session->set('chosen_shipping_methods', array( $chosen_shipping ) ); WC()->session->set('billmate_checkout_billing_country', $billing_address['country']); - WC()->session->set('billmate_checkout_billing_postcode', $billing_address['postcode']); WC()->session->set('billmate_checkout_shipping_country', $shipping_address['country']); + WC()->session->set('billmate_checkout_billing_postcode', $billing_address['postcode']); WC()->session->set('billmate_checkout_shipping_postcode', $shipping_address['postcode']); - + WC()->session->set('billmate_checkout_billing_city', $billing_address['city']); + WC()->session->set('billmate_checkout_shipping_city', $shipping_address['city']); + WC()->session->set('billmate_checkout_billing_address_1', $billing_address['address_1']); + WC()->session->set('billmate_checkout_shipping_address_1', $shipping_address['address_1']); WC()->cart->calculate_shipping(); WC()->cart->calculate_fees(); @@ -537,11 +547,13 @@ function billmate_update_address(){ } } else { + $cart = do_shortcode('[woocommerce_cart]'); $current_order_total = (int)WC_Payment_Gateway::get_order_total(); - wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total)); + wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total, 'cart' => $cart)); } + $cart = do_shortcode('[woocommerce_cart]'); $current_order_total = (int)WC_Payment_Gateway::get_order_total(); - wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total)); + wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total, 'cart' => $cart)); } } @@ -888,6 +900,7 @@ function get_url(){ $current_order_total = (int)WC_Payment_Gateway::get_order_total(); if ($previous_order_total != $current_order_total) { $this->updateCheckoutFromOrderId( $orderId ); + } $checkout = $billmate->getCheckout(array('PaymentData' => array('hash' => WC()->session->get( 'billmate_checkout_hash' )))); @@ -1020,6 +1033,12 @@ public function updateCheckoutFromOrderId( $orderId = null ) 'number' => $checkoutOrderNumber ); WC()->session->set('billmate_previous_calculated_order_total', WC_Payment_Gateway::get_order_total()); + if (count(debug_backtrace()) < 25) { + do_action('billmate_checkout_save_shipping_method'); + } + else { + WC()->session->set('billmate_update_cart_timestamp', time()); + } return $billmate->updateCheckout($orderValues); } return array(); @@ -1030,7 +1049,7 @@ function initCheckout($orderId = null){ $billmate = $this->getBillmateConnection(); $result = $billmate->initCheckout($orderValues); - + do_action('billmate_checkout_save_shipping_method'); // Save checkout hash if(!isset($result['code']) AND isset($result['url']) AND $result['url'] != "") { $url = $result['url']; @@ -1131,7 +1150,7 @@ public function updateCheckout($result, $order) WC()->session->set('billmate_previous_calculated_order_total', WC_Payment_Gateway::get_order_total()); $data = $billmate->updateCheckout($orderValues); - + do_action('billmate_checkout_save_shipping_method'); if(!isset($data['code'])){ $current_order_total = (int)WC_Payment_Gateway::get_order_total(); if($previousTotal != $orderValues['Cart']['Total']['withtax']){ diff --git a/woocommerce-gateway-billmate/commonfunctions.php b/woocommerce-gateway-billmate/commonfunctions.php index b299e709..677414c6 100644 --- a/woocommerce-gateway-billmate/commonfunctions.php +++ b/woocommerce-gateway-billmate/commonfunctions.php @@ -10,6 +10,24 @@ if (!function_exists('is_plugin_active')) { require_once(ABSPATH.'wp-admin/includes/plugin.php'); } +add_action('billmate_checkout_save_shipping_method', 'updateshipping'); +add_action('woocommerce_proceed_to_checkout', 'updatecartshipping'); + +function updatecartshipping() { + $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); + $chosen_shipping = $chosen_methods[0]; + if ($chosen_shipping !== null && is_cart() && (time() - WC()->session->get( 'billmate_update_cart_timestamp') > 5)) { + WC()->session->set('billmate_checkout_saved_shipping_method', $chosen_shipping); + } +} + +function updateshipping() { + $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); + $chosen_shipping = $chosen_methods[0]; + if ($chosen_shipping !== null) { + WC()->session->set('billmate_checkout_saved_shipping_method', $chosen_shipping); + } +} function convertToUTF8($str) { $enc = mb_detect_encoding($str); diff --git a/woocommerce-gateway-billmate/js/billmatecheckout.js b/woocommerce-gateway-billmate/js/billmatecheckout.js index 370577ac..5ce4a1cc 100644 --- a/woocommerce-gateway-billmate/js/billmatecheckout.js +++ b/woocommerce-gateway-billmate/js/billmatecheckout.js @@ -69,6 +69,9 @@ var BillmateIframe = new function(){ } else { self.hideCheckoutLoading(); } + if (response.data.hasOwnProperty('cart')){ + document.getElementsByClassName("woocommerce")[0].innerHTML = response.data.cart; + } } });