/**
  * Set customer shipping address to base address.
  * @since 2.7.0
  * @throws WC_Data_Exception
  */
 public function set_shipping_address_to_base()
 {
     $base = wc_get_customer_default_location();
     $this->data['shipping']['country'] = $base['country'];
     $this->data['shipping']['state'] = $base['state'];
     $this->data['shipping']['postcode'] = '';
     $this->data['shipping']['city'] = '';
 }
Example #2
0
 /**
  * Test setting a customer's shipping address to the base address.
  * @since 2.7.0
  */
 public function test_customer_set_shipping_address_to_base()
 {
     $customer = WC_Helper_Customer::create_customer();
     $customer->set_shipping_address_to_base();
     $base = wc_get_customer_default_location();
     $this->assertEquals($base['country'], $customer->get_shipping_country());
     $this->assertEquals($base['state'], $customer->get_shipping_state());
     $this->assertEmpty($customer->get_shipping_postcode());
     $this->assertEmpty($customer->get_shipping_city());
 }
 /**
  * Get default state for a customer
  *
  * @return string
  */
 public function get_default_state()
 {
     $default = wc_get_customer_default_location();
     return $default['state'];
 }
 /**
  * Set customer shipping address to base address.
  *
  * @since 2.7.0
  * @throws WC_Data_Exception
  */
 public function set_shipping_address_to_base()
 {
     $base = wc_get_customer_default_location();
     $this->set_shipping_location($base['country'], $base['state'], '', '');
 }
 /**
  * Get default state for a customer.
  * @return string
  */
 public function get_default_state()
 {
     _deprecated_function('WC_Customer::get_default_state', '2.7', 'wc_get_customer_default_location');
     $default = wc_get_customer_default_location();
     return $default['state'];
 }
 public function get_location_for_current_user()
 {
     global $woocommerce;
     $location = false;
     if (is_user_logged_in()) {
         $location = get_user_meta(get_current_user_id(), '_wc_location', true);
     }
     if (!empty($location)) {
         return $location;
     }
     $session =& WC_Catalog_Visibility_Compatibility::WC()->session;
     $location = isset($session) && isset($session->wc_location) ? $session->wc_location : '';
     if (empty($location) && function_exists('wc_get_customer_default_location') && $this->get_setting('_wc_restrictions_locations_use_geo', 'yes') == 'yes') {
         $l = wc_get_customer_default_location();
         if (isset($l['country'])) {
             $location = $l['country'];
         }
     }
     return apply_filters('woocommerce_catalog_restrictions_get_user_location', $location);
 }
 /**
  * Load default values if props are unset.
  *
  * @param WC_Customer
  */
 protected function set_defaults(&$customer)
 {
     $default = wc_get_customer_default_location();
     if (!$customer->get_billing_country()) {
         $customer->set_billing_country($default['country']);
     }
     if (!$customer->get_shipping_country()) {
         $customer->set_shipping_country($customer->get_billing_country());
     }
     if (!$customer->get_billing_state()) {
         $customer->set_billing_state($default['state']);
     }
     if (!$customer->get_shipping_state()) {
         $customer->set_shipping_state($customer->get_billing_state());
     }
     if (!$customer->get_billing_email() && is_user_logged_in()) {
         $current_user = wp_get_current_user();
         $customer->set_billing_email($current_user->user_email);
     }
 }
    ?>
</h2>
<?php 
}
?>

<form id="add_address_form">
    <div class="shipping_address address_block" id="shipping_address">
        <?php 
do_action('woocommerce_before_checkout_shipping_form', $checkout);
?>

        <div class="address-column">
            <?php 
if (function_exists('wc_get_customer_default_location')) {
    $location = wc_get_customer_default_location();
    if (empty($address) && !empty($location)) {
        foreach ($location as $key => $value) {
            $address['shipping_' . $key] = $value;
        }
    }
}
foreach ($shipFields as $key => $field) {
    $val = isset($address[$key]) ? $address[$key] : '';
    $id = rtrim(str_replace('[', '_', $key), ']');
    $field['return'] = true;
    echo str_replace('name="' . $key . '"', 'name="address[' . $id . ']"', woocommerce_form_field($key, $field, $val));
}
do_action('woocommerce_after_checkout_shipping_form', $checkout);
?>
            <input type="hidden" name="id" id="address_id" value="<?php