/**
  * Create a mock customer for testing purposes.
  *
  * @return WC_Customer
  */
 public static function create_mock_customer()
 {
     $customer_data = array('country' => 'US', 'state' => 'PA', 'postcode' => '19123', 'city' => 'Philadelphia', 'address' => '123 South Street', 'address_2' => 'Apt 1', 'shipping_country' => 'US', 'shipping_state' => 'PA', 'shipping_postcode' => '19123', 'shipping_city' => 'Philadelphia', 'shipping_address' => '123 South Street', 'shipping_address_2' => 'Apt 1', 'is_vat_exempt' => false, 'calculated_shipping' => false);
     WC_Helper_Customer::set_customer_details($customer_data);
     $customer = new WC_Customer();
     $customer->load_session();
     return $customer;
 }
 /**
  * Get a hash of the customer location.
  * @return string
  */
 public static function geolocation_ajax_get_location_hash()
 {
     $customer = new WC_Customer();
     $customer->load_session();
     $location = array();
     $location['country'] = $customer->get_billing_country();
     $location['state'] = $customer->get_billing_state();
     $location['postcode'] = $customer->get_billing_postcode();
     $location['city'] = $customer->get_billing_city();
     return substr(md5(implode('', $location)), 0, 12);
 }
Esempio n. 3
0
 /**
  * Test WC_Customer's session handling code.
  * @since 2.7.0
  */
 public function test_customer_sessions()
 {
     $customer = WC_Helper_Customer::create_customer();
     $session = WC_Helper_Customer::create_mock_customer();
     // set into session....
     $this->assertEquals('19123', $session->get_billing_postcode());
     $this->assertEquals('123 South Street', $session->get_billing_address());
     $this->assertEquals('Philadelphia', $session->get_billing_city());
     $session->set_billing_address('124 South Street');
     $session->save_to_session();
     $session = new WC_Customer(0, true);
     $session->load_session();
     $this->assertEquals('124 South Street', $session->get_billing_address());
     $session = new WC_Customer(0, true);
     $session->load_session();
     $session->set_billing_postcode('32191');
     $session->save();
     // should still be session ID, not a created row, since we are working with guests/sessions
     $this->assertFalse($session->get_id() > 0);
     $this->assertEquals('32191', $session->get_billing_postcode());
 }