WC_Customer

The WooCommerce customer class handles storage of the current customer's data, such as location.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-customer.php  
  1. class WC_Customer extends WC_Legacy_Customer { 
  2.  
  3. /** 
  4. * Stores customer data. 
  5. * @var array 
  6. */ 
  7. protected $data = array( 
  8. 'date_created' => null,  
  9. 'date_modified' => null,  
  10. 'email' => '',  
  11. 'first_name' => '',  
  12. 'last_name' => '',  
  13. 'role' => 'customer',  
  14. 'username' => '',  
  15. 'billing' => array( 
  16. 'first_name' => '',  
  17. 'last_name' => '',  
  18. 'company' => '',  
  19. 'address_1' => '',  
  20. 'address_2' => '',  
  21. 'city' => '',  
  22. 'state' => '',  
  23. 'postcode' => '',  
  24. 'country' => '',  
  25. 'email' => '',  
  26. 'phone' => '',  
  27. ),  
  28. 'shipping' => array( 
  29. 'first_name' => '',  
  30. 'last_name' => '',  
  31. 'company' => '',  
  32. 'address_1' => '',  
  33. 'address_2' => '',  
  34. 'city' => '',  
  35. 'state' => '',  
  36. 'postcode' => '',  
  37. 'country' => '',  
  38. ),  
  39. 'is_paying_customer' => false,  
  40. ); 
  41.  
  42. /** 
  43. * Stores a password if this needs to be changed. Write-only and hidden from _data. 
  44. * @var string 
  45. */ 
  46. protected $password = ''; 
  47.  
  48. /** 
  49. * Stores if user is VAT exempt for this session. 
  50. * @var string 
  51. */ 
  52. protected $is_vat_exempt = false; 
  53.  
  54. /** 
  55. * Stores if user has calculated shipping in this session. 
  56. * @var string 
  57. */ 
  58. protected $calculated_shipping = false; 
  59.  
  60. /** 
  61. * Load customer data based on how WC_Customer is called. 
  62. * If $customer is 'new', you can build a new WC_Customer object. If it's empty, some 
  63. * data will be pulled from the session for the current user/customer. 
  64. * @param WC_Customer|int $data Customer ID or data. 
  65. * @param bool $is_session True if this is the customer session 
  66. * @throws Exception if customer cannot be read/found and $data is set. 
  67. */ 
  68. public function __construct( $data = 0, $is_session = false ) { 
  69. parent::__construct( $data ); 
  70.  
  71. if ( $data instanceof WC_Customer ) { 
  72. $this->set_id( absint( $data->get_id() ) ); 
  73. } elseif ( is_numeric( $data ) ) { 
  74. $this->set_id( $data ); 
  75.  
  76. $this->data_store = WC_Data_Store::load( 'customer' ); 
  77.  
  78. // If we have an ID, load the user from the DB. 
  79. if ( $this->get_id() ) { 
  80. try { 
  81. $this->data_store->read( $this ); 
  82. } catch ( Exception $e ) { 
  83. $this->set_id( 0 ); 
  84. $this->set_object_read( true ); 
  85. } else { 
  86. $this->set_object_read( true ); 
  87.  
  88. // If this is a session, set or change the data store to sessions. Changes do not persist in the database. 
  89. if ( $is_session ) { 
  90. $this->data_store = WC_Data_Store::load( 'customer-session' ); 
  91. $this->data_store->read( $this ); 
  92.  
  93. /** 
  94. * Prefix for action and filter hooks on data. 
  95. * @since 3.0.0 
  96. * @return string 
  97. */ 
  98. protected function get_hook_prefix() { 
  99. return 'woocommerce_customer_get_'; 
  100.  
  101. /** 
  102. * Delete a customer and reassign posts.. 
  103. * @param int $reassign Reassign posts and links to new User ID. 
  104. * @since 3.0.0 
  105. * @return bool 
  106. */ 
  107. public function delete_and_reassign( $reassign = null ) { 
  108. if ( $this->data_store ) { 
  109. $this->data_store->delete( $this, array( 'force_delete' => true, 'reassign' => $reassign ) ); 
  110. $this->set_id( 0 ); 
  111. return true; 
  112. return false; 
  113.  
  114. /** 
  115. * Is customer outside base country (for tax purposes)? 
  116. * @return bool 
  117. */ 
  118. public function is_customer_outside_base() { 
  119. list( $country, $state ) = $this->get_taxable_address(); 
  120. if ( $country ) { 
  121. $default = wc_get_base_location(); 
  122. if ( $default['country'] !== $country ) { 
  123. return true; 
  124. if ( $default['state'] && $default['state'] !== $state ) { 
  125. return true; 
  126. return false; 
  127.  
  128. /** 
  129. * Return this customer's avatar. 
  130. * @since 3.0.0 
  131. * @return string 
  132. */ 
  133. public function get_avatar_url() { 
  134. $avatar_html = get_avatar( $this->get_email() ); 
  135.  
  136. // Get the URL of the avatar from the provided HTML 
  137. preg_match( '/src=["|\'](.+)[\&|"|\']/U', $avatar_html, $matches ); 
  138.  
  139. if ( isset( $matches[1] ) && ! empty( $matches[1] ) ) { 
  140. return esc_url( $matches[1] ); 
  141.  
  142. return ''; 
  143.  
  144. /** 
  145. * Get taxable address. 
  146. * @return array 
  147. */ 
  148. public function get_taxable_address() { 
  149. $tax_based_on = get_option( 'woocommerce_tax_based_on' ); 
  150.  
  151. // Check shipping method at this point to see if we need special handling 
  152. if ( true === apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true ) && sizeof( array_intersect( wc_get_chosen_shipping_method_ids(), apply_filters( 'woocommerce_local_pickup_methods', array( 'legacy_local_pickup', 'local_pickup' ) ) ) ) > 0 ) { 
  153. $tax_based_on = 'base'; 
  154.  
  155. if ( 'base' === $tax_based_on ) { 
  156. $country = WC()->countries->get_base_country(); 
  157. $state = WC()->countries->get_base_state(); 
  158. $postcode = WC()->countries->get_base_postcode(); 
  159. $city = WC()->countries->get_base_city(); 
  160. } elseif ( 'billing' === $tax_based_on ) { 
  161. $country = $this->get_billing_country(); 
  162. $state = $this->get_billing_state(); 
  163. $postcode = $this->get_billing_postcode(); 
  164. $city = $this->get_billing_city(); 
  165. } else { 
  166. $country = $this->get_shipping_country(); 
  167. $state = $this->get_shipping_state(); 
  168. $postcode = $this->get_shipping_postcode(); 
  169. $city = $this->get_shipping_city(); 
  170.  
  171. return apply_filters( 'woocommerce_customer_taxable_address', array( $country, $state, $postcode, $city ) ); 
  172.  
  173. /** 
  174. * Gets a customer's downloadable products. 
  175. * @return array Array of downloadable products 
  176. */ 
  177. public function get_downloadable_products() { 
  178. $downloads = array(); 
  179. if ( $this->get_id() ) { 
  180. $downloads = wc_get_customer_available_downloads( $this->get_id() ); 
  181. return apply_filters( 'woocommerce_customer_get_downloadable_products', $downloads ); 
  182.  
  183. /** 
  184. * Is customer VAT exempt? 
  185. * @return bool 
  186. */ 
  187. public function is_vat_exempt() { 
  188. return $this->get_is_vat_exempt(); 
  189.  
  190. /** 
  191. * Has calculated shipping? 
  192. * @return bool 
  193. */ 
  194. public function has_calculated_shipping() { 
  195. return $this->get_calculated_shipping(); 
  196.  
  197. /** 
  198. * Get if customer is VAT exempt? 
  199. * @since 3.0.0 
  200. * @return bool 
  201. */ 
  202. public function get_is_vat_exempt() { 
  203. return $this->is_vat_exempt; 
  204.  
  205. /** 
  206. * Get password (only used when updating the user object). 
  207. * @return string 
  208. */ 
  209. public function get_password() { 
  210. return $this->password; 
  211.  
  212. /** 
  213. * Has customer calculated shipping? 
  214. * @param string $context 
  215. * @return bool 
  216. */ 
  217. public function get_calculated_shipping() { 
  218. return $this->calculated_shipping; 
  219.  
  220. /** 
  221. * Set if customer has tax exemption. 
  222. * @param bool $is_vat_exempt 
  223. */ 
  224. public function set_is_vat_exempt( $is_vat_exempt ) { 
  225. $this->is_vat_exempt = (bool) $is_vat_exempt; 
  226.  
  227. /** 
  228. * Calculated shipping? 
  229. * @param boolean $calculated 
  230. */ 
  231. public function set_calculated_shipping( $calculated = true ) { 
  232. $this->calculated_shipping = (bool) $calculated; 
  233.  
  234. /** 
  235. * Set customer's password. 
  236. * @since 3.0.0 
  237. * @param string $password 
  238. * @throws WC_Data_Exception 
  239. */ 
  240. public function set_password( $password ) { 
  241. $this->password = wc_clean( $password ); 
  242.  
  243. /** 
  244. * Gets the customers last order. 
  245. * @param WC_Customer 
  246. * @return WC_Order|false 
  247. */ 
  248. public function get_last_order() { 
  249. return $this->data_store->get_last_order( $this ); 
  250.  
  251. /** 
  252. * Return the number of orders this customer has. 
  253. * @param WC_Customer 
  254. * @return integer 
  255. */ 
  256. public function get_order_count() { 
  257. return $this->data_store->get_order_count( $this ); 
  258.  
  259. /** 
  260. * Return how much money this customer has spent. 
  261. * @param WC_Customer 
  262. * @return float 
  263. */ 
  264. public function get_total_spent() { 
  265. return $this->data_store->get_total_spent( $this ); 
  266.  
  267. /** 
  268. |-------------------------------------------------------------------------- 
  269. | Getters 
  270. |-------------------------------------------------------------------------- 
  271. */ 
  272.  
  273. /** 
  274. * Return the customer's username. 
  275. * @since 3.0.0 
  276. * @param string $context 
  277. * @return string 
  278. */ 
  279. public function get_username( $context = 'view' ) { 
  280. return $this->get_prop( 'username', $context ); 
  281.  
  282. /** 
  283. * Return the customer's email. 
  284. * @since 3.0.0 
  285. * @param string $context 
  286. * @return string 
  287. */ 
  288. public function get_email( $context = 'view' ) { 
  289. return $this->get_prop( 'email', $context ); 
  290.  
  291. /** 
  292. * Return customer's first name. 
  293. * @since 3.0.0 
  294. * @param string $context 
  295. * @return string 
  296. */ 
  297. public function get_first_name( $context = 'view' ) { 
  298. return $this->get_prop( 'first_name', $context ); 
  299.  
  300. /** 
  301. * Return customer's last name. 
  302. * @since 3.0.0 
  303. * @param string $context 
  304. * @return string 
  305. */ 
  306. public function get_last_name( $context = 'view' ) { 
  307. return $this->get_prop( 'last_name', $context ); 
  308.  
  309. /** 
  310. * Return customer's user role. 
  311. * @since 3.0.0 
  312. * @param string $context 
  313. * @return string 
  314. */ 
  315. public function get_role( $context = 'view' ) { 
  316. return $this->get_prop( 'role', $context ); 
  317.  
  318. /** 
  319. * Return the date this customer was created. 
  320. * @since 3.0.0 
  321. * @param string $context 
  322. * @return WC_DateTime|null object if the date is set or null if there is no date. 
  323. */ 
  324. public function get_date_created( $context = 'view' ) { 
  325. return $this->get_prop( 'date_created', $context ); 
  326.  
  327. /** 
  328. * Return the date this customer was last updated. 
  329. * @since 3.0.0 
  330. * @param string $context 
  331. * @return WC_DateTime|null object if the date is set or null if there is no date. 
  332. */ 
  333. public function get_date_modified( $context = 'view' ) { 
  334. return $this->get_prop( 'date_modified', $context ); 
  335.  
  336. /** 
  337. * Gets a prop for a getter method. 
  338. * @since 3.0.0 
  339. * @param string $prop Name of prop to get. 
  340. * @param string $address billing or shipping. 
  341. * @param string $context What the value is for. Valid values are view and edit. 
  342. * @return mixed 
  343. */ 
  344. protected function get_address_prop( $prop, $address = 'billing', $context = 'view' ) { 
  345. $value = null; 
  346.  
  347. if ( array_key_exists( $prop, $this->data[ $address ] ) ) { 
  348. $value = isset( $this->changes[ $address ][ $prop ] ) ? $this->changes[ $address ][ $prop ] : $this->data[ $address ][ $prop ]; 
  349.  
  350. if ( 'view' === $context ) { 
  351. $value = apply_filters( $this->get_hook_prefix() . $address . '_' . $prop, $value, $this ); 
  352. return $value; 
  353.  
  354. /** 
  355. * Get billing_first_name. 
  356. * @param string $context 
  357. * @return string 
  358. */ 
  359. public function get_billing_first_name( $context = 'view' ) { 
  360. return $this->get_address_prop( 'first_name', 'billing', $context ); 
  361.  
  362. /** 
  363. * Get billing_last_name. 
  364. * @param string $context 
  365. * @return string 
  366. */ 
  367. public function get_billing_last_name( $context = 'view' ) { 
  368. return $this->get_address_prop( 'last_name', 'billing', $context ); 
  369.  
  370. /** 
  371. * Get billing_company. 
  372. * @param string $context 
  373. * @return string 
  374. */ 
  375. public function get_billing_company( $context = 'view' ) { 
  376. return $this->get_address_prop( 'company', 'billing', $context ); 
  377.  
  378. /** 
  379. * Get billing_address_1. 
  380. * @param string $context 
  381. * @return string 
  382. */ 
  383. public function get_billing_address( $context = 'view' ) { 
  384. return $this->get_billing_address_1( $context ); 
  385.  
  386. /** 
  387. * Get billing_address_1. 
  388. * @param string $context 
  389. * @return string 
  390. */ 
  391. public function get_billing_address_1( $context = 'view' ) { 
  392. return $this->get_address_prop( 'address_1', 'billing', $context ); 
  393.  
  394. /** 
  395. * Get billing_address_2. 
  396. * @param string $context 
  397. * @return string $value 
  398. */ 
  399. public function get_billing_address_2( $context = 'view' ) { 
  400. return $this->get_address_prop( 'address_2', 'billing', $context ); 
  401.  
  402. /** 
  403. * Get billing_city. 
  404. * @param string $context 
  405. * @return string $value 
  406. */ 
  407. public function get_billing_city( $context = 'view' ) { 
  408. return $this->get_address_prop( 'city', 'billing', $context ); 
  409.  
  410. /** 
  411. * Get billing_state. 
  412. * @param string $context 
  413. * @return string 
  414. */ 
  415. public function get_billing_state( $context = 'view' ) { 
  416. return $this->get_address_prop( 'state', 'billing', $context ); 
  417.  
  418. /** 
  419. * Get billing_postcode. 
  420. * @param string $context 
  421. * @return string 
  422. */ 
  423. public function get_billing_postcode( $context = 'view' ) { 
  424. return $this->get_address_prop( 'postcode', 'billing', $context ); 
  425.  
  426. /** 
  427. * Get billing_country. 
  428. * @param string $context 
  429. * @return string 
  430. */ 
  431. public function get_billing_country( $context = 'view' ) { 
  432. return $this->get_address_prop( 'country', 'billing', $context ); 
  433.  
  434. /** 
  435. * Get billing_email. 
  436. * @param string $context 
  437. * @return string 
  438. */ 
  439. public function get_billing_email( $context = 'view' ) { 
  440. return $this->get_address_prop( 'email', 'billing', $context ); 
  441.  
  442. /** 
  443. * Get billing_phone. 
  444. * @param string $context 
  445. * @return string 
  446. */ 
  447. public function get_billing_phone( $context = 'view' ) { 
  448. return $this->get_address_prop( 'phone', 'billing', $context ); 
  449.  
  450. /** 
  451. * Get shipping_first_name. 
  452. * @param string $context 
  453. * @return string 
  454. */ 
  455. public function get_shipping_first_name( $context = 'view' ) { 
  456. return $this->get_address_prop( 'first_name', 'shipping', $context ); 
  457.  
  458. /** 
  459. * Get shipping_last_name. 
  460. * @param string $context 
  461. * @return string 
  462. */ 
  463. public function get_shipping_last_name( $context = 'view' ) { 
  464. return $this->get_address_prop( 'last_name', 'shipping', $context ); 
  465.  
  466. /** 
  467. * Get shipping_company. 
  468. * @param string $context 
  469. * @return string 
  470. */ 
  471. public function get_shipping_company( $context = 'view' ) { 
  472. return $this->get_address_prop( 'company', 'shipping', $context ); 
  473.  
  474. /** 
  475. * Get shipping_address_1. 
  476. * @param string $context 
  477. * @return string 
  478. */ 
  479. public function get_shipping_address( $context = 'view' ) { 
  480. return $this->get_shipping_address_1( $context ); 
  481.  
  482. /** 
  483. * Get shipping_address_1. 
  484. * @param string $context 
  485. * @return string 
  486. */ 
  487. public function get_shipping_address_1( $context = 'view' ) { 
  488. return $this->get_address_prop( 'address_1', 'shipping', $context ); 
  489.  
  490. /** 
  491. * Get shipping_address_2. 
  492. * @param string $context 
  493. * @return string 
  494. */ 
  495. public function get_shipping_address_2( $context = 'view' ) { 
  496. return $this->get_address_prop( 'address_2', 'shipping', $context ); 
  497.  
  498. /** 
  499. * Get shipping_city. 
  500. * @param string $context 
  501. * @return string 
  502. */ 
  503. public function get_shipping_city( $context = 'view' ) { 
  504. return $this->get_address_prop( 'city', 'shipping', $context ); 
  505.  
  506. /** 
  507. * Get shipping_state. 
  508. * @param string $context 
  509. * @return string 
  510. */ 
  511. public function get_shipping_state( $context = 'view' ) { 
  512. return $this->get_address_prop( 'state', 'shipping', $context ); 
  513.  
  514. /** 
  515. * Get shipping_postcode. 
  516. * @param string $context 
  517. * @return string 
  518. */ 
  519. public function get_shipping_postcode( $context = 'view' ) { 
  520. return $this->get_address_prop( 'postcode', 'shipping', $context ); 
  521.  
  522. /** 
  523. * Get shipping_country. 
  524. * @param string $context 
  525. * @return string 
  526. */ 
  527. public function get_shipping_country( $context = 'view' ) { 
  528. return $this->get_address_prop( 'country', 'shipping', $context ); 
  529.  
  530. /** 
  531. * Is the user a paying customer? 
  532. * @since 3.0.0 
  533. * @param string $context 
  534. * @return bool 
  535. */ 
  536. function get_is_paying_customer( $context = 'view' ) { 
  537. return $this->get_prop( 'is_paying_customer', $context ); 
  538.  
  539. /** 
  540. |-------------------------------------------------------------------------- 
  541. | Setters 
  542. |-------------------------------------------------------------------------- 
  543. */ 
  544.  
  545. /** 
  546. * Set customer's username. 
  547. * @since 3.0.0 
  548. * @param string $username 
  549. * @throws WC_Data_Exception 
  550. */ 
  551. public function set_username( $username ) { 
  552. $this->set_prop( 'username', $username ); 
  553.  
  554. /** 
  555. * Set customer's email. 
  556. * @since 3.0.0 
  557. * @param string $value 
  558. * @throws WC_Data_Exception 
  559. */ 
  560. public function set_email( $value ) { 
  561. if ( $value && ! is_email( $value ) ) { 
  562. $this->error( 'customer_invalid_email', __( 'Invalid email address', 'woocommerce' ) ); 
  563. $this->set_prop( 'email', sanitize_email( $value ) ); 
  564.  
  565. /** 
  566. * Set customer's first name. 
  567. * @since 3.0.0 
  568. * @param string $first_name 
  569. * @throws WC_Data_Exception 
  570. */ 
  571. public function set_first_name( $first_name ) { 
  572. $this->set_prop( 'first_name', $first_name ); 
  573.  
  574. /** 
  575. * Set customer's last name. 
  576. * @since 3.0.0 
  577. * @param string $last_name 
  578. * @throws WC_Data_Exception 
  579. */ 
  580. public function set_last_name( $last_name ) { 
  581. $this->set_prop( 'last_name', $last_name ); 
  582.  
  583. /** 
  584. * Set customer's user role(s). 
  585. * @since 3.0.0 
  586. * @param mixed $role 
  587. * @throws WC_Data_Exception 
  588. */ 
  589. public function set_role( $role ) { 
  590. global $wp_roles; 
  591.  
  592. if ( $role && ! empty( $wp_roles->roles ) && ! in_array( $role, array_keys( $wp_roles->roles ) ) ) { 
  593. $this->error( 'customer_invalid_role', __( 'Invalid role', 'woocommerce' ) ); 
  594. $this->set_prop( 'role', $role ); 
  595.  
  596. /** 
  597. * Set the date this customer was last updated. 
  598. * @since 3.0.0 
  599. * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date. 
  600. * @throws WC_Data_Exception 
  601. */ 
  602. public function set_date_created( $date = null ) { 
  603. $this->set_date_prop( 'date_created', $date ); 
  604.  
  605. /** 
  606. * Set the date this customer was last updated. 
  607. * @since 3.0.0 
  608. * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date. 
  609. * @throws WC_Data_Exception 
  610. */ 
  611. public function set_date_modified( $date = null ) { 
  612. $this->set_date_prop( 'date_modified', $date ); 
  613.  
  614. /** 
  615. * Set customer address to match shop base address. 
  616. * @since 3.0.0 
  617. * @throws WC_Data_Exception 
  618. */ 
  619. public function set_billing_address_to_base() { 
  620. $base = wc_get_customer_default_location(); 
  621. $this->set_billing_location( $base['country'], $base['state'], '', '' ); 
  622.  
  623. /** 
  624. * Set customer shipping address to base address. 
  625. * @since 3.0.0 
  626. * @throws WC_Data_Exception 
  627. */ 
  628. public function set_shipping_address_to_base() { 
  629. $base = wc_get_customer_default_location(); 
  630. $this->set_shipping_location( $base['country'], $base['state'], '', '' ); 
  631.  
  632. /** 
  633. * Sets all address info at once. 
  634. * @param string $country 
  635. * @param string $state 
  636. * @param string $postcode 
  637. * @param string $city 
  638. * @throws WC_Data_Exception 
  639. */ 
  640. public function set_billing_location( $country, $state = '', $postcode = '', $city = '' ) { 
  641. $billing = $this->get_prop( 'billing', 'edit' ); 
  642. $billing['country'] = $country; 
  643. $billing['state'] = $state; 
  644. $billing['postcode'] = $postcode; 
  645. $billing['city'] = $city; 
  646. $this->set_prop( 'billing', $billing ); 
  647.  
  648. /** 
  649. * Sets all shipping info at once. 
  650. * @param string $country 
  651. * @param string $state 
  652. * @param string $postcode 
  653. * @param string $city 
  654. * @throws WC_Data_Exception 
  655. */ 
  656. public function set_shipping_location( $country, $state = '', $postcode = '', $city = '' ) { 
  657. $shipping = $this->get_prop( 'shipping', 'edit' ); 
  658. $shipping['country'] = $country; 
  659. $shipping['state'] = $state; 
  660. $shipping['postcode'] = $postcode; 
  661. $shipping['city'] = $city; 
  662. $this->set_prop( 'shipping', $shipping ); 
  663.  
  664. /** 
  665. * Sets a prop for a setter method. 
  666. * @since 3.0.0 
  667. * @param string $prop Name of prop to set. 
  668. * @param string $address Name of address to set. billing or shipping. 
  669. * @param mixed $value Value of the prop. 
  670. */ 
  671. protected function set_address_prop( $prop, $address = 'billing', $value ) { 
  672. if ( array_key_exists( $prop, $this->data[ $address ] ) ) { 
  673. if ( true === $this->object_read ) { 
  674. if ( $value !== $this->data[ $address ][ $prop ] || ( isset( $this->changes[ $address ] ) && array_key_exists( $prop, $this->changes[ $address ] ) ) ) { 
  675. $this->changes[ $address ][ $prop ] = $value; 
  676. } else { 
  677. $this->data[ $address ][ $prop ] = $value; 
  678.  
  679. /** 
  680. * Set billing_first_name. 
  681. * @param string $value 
  682. * @throws WC_Data_Exception 
  683. */ 
  684. public function set_billing_first_name( $value ) { 
  685. $this->set_address_prop( 'first_name', 'billing', $value ); 
  686.  
  687. /** 
  688. * Set billing_last_name. 
  689. * @param string $value 
  690. * @throws WC_Data_Exception 
  691. */ 
  692. public function set_billing_last_name( $value ) { 
  693. $this->set_address_prop( 'last_name', 'billing', $value ); 
  694.  
  695. /** 
  696. * Set billing_company. 
  697. * @param string $value 
  698. * @throws WC_Data_Exception 
  699. */ 
  700. public function set_billing_company( $value ) { 
  701. $this->set_address_prop( 'company', 'billing', $value ); 
  702.  
  703. /** 
  704. * Set billing_address_1. 
  705. * @param string $value 
  706. * @throws WC_Data_Exception 
  707. */ 
  708. public function set_billing_address( $value ) { 
  709. $this->set_billing_address_1( $value ); 
  710.  
  711. /** 
  712. * Set billing_address_1. 
  713. * @param string $value 
  714. * @throws WC_Data_Exception 
  715. */ 
  716. public function set_billing_address_1( $value ) { 
  717. $this->set_address_prop( 'address_1', 'billing', $value ); 
  718.  
  719. /** 
  720. * Set billing_address_2. 
  721. * @param string $value 
  722. * @throws WC_Data_Exception 
  723. */ 
  724. public function set_billing_address_2( $value ) { 
  725. $this->set_address_prop( 'address_2', 'billing', $value ); 
  726.  
  727. /** 
  728. * Set billing_city. 
  729. * @param string $value 
  730. * @throws WC_Data_Exception 
  731. */ 
  732. public function set_billing_city( $value ) { 
  733. $this->set_address_prop( 'city', 'billing', $value ); 
  734.  
  735. /** 
  736. * Set billing_state. 
  737. * @param string $value 
  738. * @throws WC_Data_Exception 
  739. */ 
  740. public function set_billing_state( $value ) { 
  741. $this->set_address_prop( 'state', 'billing', $value ); 
  742.  
  743. /** 
  744. * Set billing_postcode. 
  745. * @param string $value 
  746. * @throws WC_Data_Exception 
  747. */ 
  748. public function set_billing_postcode( $value ) { 
  749. $this->set_address_prop( 'postcode', 'billing', $value ); 
  750.  
  751. /** 
  752. * Set billing_country. 
  753. * @param string $value 
  754. * @throws WC_Data_Exception 
  755. */ 
  756. public function set_billing_country( $value ) { 
  757. $this->set_address_prop( 'country', 'billing', $value ); 
  758.  
  759. /** 
  760. * Set billing_email. 
  761. * @param string $value 
  762. * @throws WC_Data_Exception 
  763. */ 
  764. public function set_billing_email( $value ) { 
  765. if ( $value && ! is_email( $value ) ) { 
  766. $this->error( 'customer_invalid_billing_email', __( 'Invalid billing email address', 'woocommerce' ) ); 
  767. $this->set_address_prop( 'email', 'billing', sanitize_email( $value ) ); 
  768.  
  769. /** 
  770. * Set billing_phone. 
  771. * @param string $value 
  772. * @throws WC_Data_Exception 
  773. */ 
  774. public function set_billing_phone( $value ) { 
  775. $this->set_address_prop( 'phone', 'billing', $value ); 
  776.  
  777. /** 
  778. * Set shipping_first_name. 
  779. * @param string $value 
  780. * @throws WC_Data_Exception 
  781. */ 
  782. public function set_shipping_first_name( $value ) { 
  783. $this->set_address_prop( 'first_name', 'shipping', $value ); 
  784.  
  785. /** 
  786. * Set shipping_last_name. 
  787. * @param string $value 
  788. * @throws WC_Data_Exception 
  789. */ 
  790. public function set_shipping_last_name( $value ) { 
  791. $this->set_address_prop( 'last_name', 'shipping', $value ); 
  792.  
  793. /** 
  794. * Set shipping_company. 
  795. * @param string $value 
  796. * @throws WC_Data_Exception 
  797. */ 
  798. public function set_shipping_company( $value ) { 
  799. $this->set_address_prop( 'company', 'shipping', $value ); 
  800.  
  801. /** 
  802. * Set shipping_address_1. 
  803. * @param string $value 
  804. * @throws WC_Data_Exception 
  805. */ 
  806. public function set_shipping_address( $value ) { 
  807. $this->set_shipping_address_1( $value ); 
  808.  
  809. /** 
  810. * Set shipping_address_1. 
  811. * @param string $value 
  812. * @throws WC_Data_Exception 
  813. */ 
  814. public function set_shipping_address_1( $value ) { 
  815. $this->set_address_prop( 'address_1', 'shipping', $value ); 
  816.  
  817. /** 
  818. * Set shipping_address_2. 
  819. * @param string $value 
  820. * @throws WC_Data_Exception 
  821. */ 
  822. public function set_shipping_address_2( $value ) { 
  823. $this->set_address_prop( 'address_2', 'shipping', $value ); 
  824.  
  825. /** 
  826. * Set shipping_city. 
  827. * @param string $value 
  828. * @throws WC_Data_Exception 
  829. */ 
  830. public function set_shipping_city( $value ) { 
  831. $this->set_address_prop( 'city', 'shipping', $value ); 
  832.  
  833. /** 
  834. * Set shipping_state. 
  835. * @param string $value 
  836. * @throws WC_Data_Exception 
  837. */ 
  838. public function set_shipping_state( $value ) { 
  839. $this->set_address_prop( 'state', 'shipping', $value ); 
  840.  
  841. /** 
  842. * Set shipping_postcode. 
  843. * @param string $value 
  844. * @throws WC_Data_Exception 
  845. */ 
  846. public function set_shipping_postcode( $value ) { 
  847. $this->set_address_prop( 'postcode', 'shipping', $value ); 
  848.  
  849. /** 
  850. * Set shipping_country. 
  851. * @param string $value 
  852. * @throws WC_Data_Exception 
  853. */ 
  854. public function set_shipping_country( $value ) { 
  855. $this->set_address_prop( 'country', 'shipping', $value ); 
  856.  
  857. /** 
  858. * Set if the user a paying customer. 
  859. * @since 3.0.0 
  860. * @param bool $is_paying_customer 
  861. * @throws WC_Data_Exception 
  862. */ 
  863. function set_is_paying_customer( $is_paying_customer ) { 
  864. $this->set_prop( 'is_paying_customer', (bool) $is_paying_customer );