title: Updating Client Woocommerce Shipping Address before checkout page
body: <p>I would like to popup a simple model on homepage and let a user choose their shipping country before the checkout/cart page. </p>
  
  <p>I made a small select box popup model and then run this function with AJAX in order to change the user shipping country but its not being updated.</p>
  
  <p>// Localizing </p>
  
  <pre><code>//*********** Ajax Change shipping country on press ***********/
  
  function localize_array() {
  
  $localize = array(
      'ajax_url' =&gt; admin_url( 'admin-ajax.php' ),
      'nonce'    =&gt; wp_create_nonce( 'yo-ajax-call-ak' ),
  );
  
  return $localize;
  
  }
  
  function ajax_change_shipping() {
  wp_enqueue_script( 'ak-country-change', get_template_directory_uri() . '/inc/js/select-country.js', array( 'jquery', ), '1.0', true );
  wp_localize_script( 'ak-country-change', 'akselect', localize_array() );
  }
  
  add_action( 'wp_enqueue_scripts', 'ajax_change_shipping' );
  </code></pre>
  
  <p>// The ajax call </p>
  
  <pre><code>$(document).ready(function () {
  
      $('body').on('change', '.yo-lang-select', function () {
  
          var select = $(this);
          var value = select.val();
          $.ajax({
              url: akselect.ajax_url,
              method: 'POST',
              dataType: 'json',
              data: {
                  action: 'get_the_defualt_lang',
                  value: value
                  nonce: akselect.nonce
              },
              success: function (respond) {
                  console.log(respond);
              },
              error: function (jqXHR, textStatus, errorThrown) {
  
                  console.log(jqXHR, textStatus, errorThrown);
  
              }
          });
      });
  
  });
  </code></pre>
  
  <p>// This is the function </p>
  
  <pre><code>add_action( 'wp_ajax_get_the_defualt_lang', 'get_the_defualt_lang' );
  add_action( 'wp_ajax_nopriv_get_the_defualt_lang','get_the_defualt_lang' );
  
  function get_the_defualt_lang() {
  
  $lang = $_POST['value'];
  
  add_action( 'woocommerce_add_to_cart', 'set_country_befor_cart_page' );
  function set_country_befor_cart_page() {
  
      WC()-&gt;customer-&gt;set_country( $lang );
      WC()-&gt;customer-&gt;set_shipping_country( $lang );
  
  }
  
  $respond = $lang;
  
  echo json_encode( $respond );
  
  
  die();
  
  }
  </code></pre>
  
  <p>// The popup form </p>
  
  <pre><code>&lt;div data-effect="mfp-zoom-out" id="shop-pop_1" class="mfp-hide"&gt;
  &lt;select class="yo-lang-select" data-type="lang" title=""&gt;
      &lt;option value="US"&gt;United States&lt;/option&gt;
      &lt;option value="GB"&gt;United Kingdom (UK)&lt;/option&gt;
      &lt;option value="US"&gt;Other Countries&lt;/option&gt;
  
  &lt;/select&gt;
  </code></pre>
  
  <p></p>
  
  <p>// Using a hook to insert the from to the shop page</p>
  
  <pre><code>add_action( 'woocommerce_after_shop_loop', 'ak_store_popup' );
  
  function ak_store_popup() {
    get_template_part( 'template-parts/popups/popup', 'store-main' );
  }
  </code></pre>