2011-08-09 15:16:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Customer
|
2012-08-14 19:42:38 +00:00
|
|
|
*
|
2011-12-08 19:45:24 +00:00
|
|
|
* The WooCommerce customer class handles storage of the current customer's data, such as location.
|
2011-08-09 15:16:18 +00:00
|
|
|
*
|
2014-11-18 14:32:48 +00:00
|
|
|
* @class WC_Customer
|
|
|
|
* @version 2.3.0
|
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @category Class
|
|
|
|
* @author WooThemes
|
|
|
|
*
|
|
|
|
* @property string $country
|
|
|
|
* @property string $state
|
|
|
|
* @property string $postcode
|
|
|
|
* @property string $city
|
|
|
|
* @property string $address
|
|
|
|
* @property string $address_2
|
|
|
|
* @property string $shipping_country
|
|
|
|
* @property string $shipping_state
|
|
|
|
* @property string $shipping_postcode
|
|
|
|
* @property string $shipping_city
|
|
|
|
* @property string $shipping_address
|
|
|
|
* @property string $shipping_address_2
|
|
|
|
* @property string $is_vat_exempt
|
|
|
|
* @property string $calculated_shipping
|
2011-08-09 15:16:18 +00:00
|
|
|
*/
|
2012-01-27 16:38:39 +00:00
|
|
|
class WC_Customer {
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
/**
|
|
|
|
* Stores customer data
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-09-23 16:16:39 +00:00
|
|
|
protected $_data;
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
/**
|
|
|
|
* Stores bool when data is changed
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
2013-01-23 12:27:15 +00:00
|
|
|
private $_changed = false;
|
2013-01-12 13:02:47 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
2012-09-07 18:28:27 +00:00
|
|
|
* Constructor for the customer class loads the customer data.
|
2012-08-14 19:42:38 +00:00
|
|
|
*
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function __construct() {
|
2014-06-02 10:50:01 +00:00
|
|
|
$this->_data = WC()->session->get( 'customer' );
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2014-06-02 10:50:01 +00:00
|
|
|
if ( empty( $this->_data ) ) {
|
2012-09-23 16:16:39 +00:00
|
|
|
$this->_data = array(
|
2014-09-22 12:23:28 +00:00
|
|
|
'country' => esc_html( $this->get_default_country() ),
|
2012-09-07 18:28:27 +00:00
|
|
|
'state' => '',
|
|
|
|
'postcode' => '',
|
2012-09-23 16:16:39 +00:00
|
|
|
'city' => '',
|
2012-11-27 01:56:48 +00:00
|
|
|
'address' => '',
|
|
|
|
'address_2' => '',
|
2014-09-22 12:23:28 +00:00
|
|
|
'shipping_country' => esc_html( $this->get_default_country() ),
|
2012-09-07 18:28:27 +00:00
|
|
|
'shipping_state' => '',
|
|
|
|
'shipping_postcode' => '',
|
2012-09-23 16:16:39 +00:00
|
|
|
'shipping_city' => '',
|
2012-11-27 01:56:48 +00:00
|
|
|
'shipping_address' => '',
|
|
|
|
'shipping_address_2' => '',
|
2012-09-07 18:28:27 +00:00
|
|
|
'is_vat_exempt' => false,
|
|
|
|
'calculated_shipping' => false
|
2012-08-14 19:42:38 +00:00
|
|
|
);
|
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-09-07 18:28:27 +00:00
|
|
|
// When leaving or ending page load, store data
|
2014-09-22 12:23:28 +00:00
|
|
|
add_action( 'shutdown', array( $this, 'save_data' ), 10 );
|
2012-09-07 18:28:27 +00:00
|
|
|
}
|
2012-09-23 16:16:39 +00:00
|
|
|
|
2013-01-12 13:02:47 +00:00
|
|
|
/**
|
2014-11-18 14:32:48 +00:00
|
|
|
* Save data function.
|
2013-01-12 13:02:47 +00:00
|
|
|
*/
|
|
|
|
public function save_data() {
|
2014-05-08 09:35:51 +00:00
|
|
|
if ( $this->_changed ) {
|
2014-06-02 10:50:01 +00:00
|
|
|
WC()->session->set( 'customer', $this->_data );
|
2014-05-08 09:35:51 +00:00
|
|
|
}
|
2013-01-12 13:02:47 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 09:03:47 +00:00
|
|
|
/**
|
|
|
|
* __set function.
|
2014-11-18 14:32:48 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @param mixed $property
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-09-22 12:23:28 +00:00
|
|
|
public function __isset( $property ) {
|
|
|
|
return isset( $this->_data[ $property ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __get function.
|
|
|
|
*
|
|
|
|
* @param string $property
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function __get( $property ) {
|
|
|
|
return isset( $this->_data[ $property ] ) ? $this->_data[ $property ] : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __set function.
|
|
|
|
*
|
|
|
|
* @param mixed $property
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
|
|
|
public function __set( $property, $value ) {
|
|
|
|
$this->_data[ $property ] = $value;
|
|
|
|
$this->_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-18 13:32:44 +00:00
|
|
|
* Get default location
|
|
|
|
* @return array
|
2014-09-22 12:23:28 +00:00
|
|
|
*/
|
2014-11-18 13:32:44 +00:00
|
|
|
public function get_default_location() {
|
2014-09-22 12:23:28 +00:00
|
|
|
$default = apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) );
|
|
|
|
|
|
|
|
if ( strstr( $default, ':' ) ) {
|
|
|
|
list( $country, $state ) = explode( ':', $default );
|
|
|
|
} else {
|
|
|
|
$country = $default;
|
|
|
|
$state = '';
|
|
|
|
}
|
|
|
|
|
2014-11-18 13:32:44 +00:00
|
|
|
return array(
|
|
|
|
'country' => $country,
|
|
|
|
'state' => $state
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get default country for a customer
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_default_country() {
|
|
|
|
$default = $this->get_default_location();
|
|
|
|
|
|
|
|
return $default['country'];
|
2014-09-22 12:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get default state for a customer
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_default_state() {
|
2014-11-18 13:32:44 +00:00
|
|
|
$default = $this->get_default_location();
|
2014-09-22 12:23:28 +00:00
|
|
|
|
2014-11-18 13:32:44 +00:00
|
|
|
return $default['state'];
|
2014-09-22 12:23:28 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-05-09 17:29:22 +00:00
|
|
|
/**
|
|
|
|
* has_calculated_shipping function.
|
2012-08-14 19:42:38 +00:00
|
|
|
*
|
2012-05-09 17:29:22 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function has_calculated_shipping() {
|
2013-01-12 13:02:47 +00:00
|
|
|
return ( ! empty( $this->calculated_shipping ) ) ? true : false;
|
2012-05-09 17:29:22 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set customer address to match shop base address.
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_to_base() {
|
2014-09-22 12:23:28 +00:00
|
|
|
$this->country = $this->get_default_country();
|
|
|
|
$this->state = $this->get_default_state();
|
|
|
|
$this->postcode = '';
|
|
|
|
$this->city = '';
|
2011-12-14 23:50:32 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set customer shipping address to base address.
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_shipping_to_base() {
|
2014-09-22 12:23:28 +00:00
|
|
|
$this->shipping_country = $this->get_default_country();
|
|
|
|
$this->shipping_state = $this->get_default_state();
|
|
|
|
$this->shipping_postcode = '';
|
|
|
|
$this->shipping_city = '';
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
2012-10-04 17:09:18 +00:00
|
|
|
* Is customer outside base country (for tax purposes)?
|
2012-08-14 19:42:38 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function is_customer_outside_base() {
|
2014-11-18 14:32:48 +00:00
|
|
|
list( $country, $state ) = $this->get_taxable_address();
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-04 17:09:18 +00:00
|
|
|
if ( $country ) {
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
$default = $this->get_default_location();
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
if ( $default['country'] !== $country ) {
|
|
|
|
return true;
|
2014-09-22 12:23:28 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
if ( $default['state'] && $default['state'] !== $state ) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-09-23 16:16:39 +00:00
|
|
|
}
|
2014-11-18 14:32:48 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-28 17:05:19 +00:00
|
|
|
|
2014-04-04 07:38:56 +00:00
|
|
|
/**
|
|
|
|
* Is the user a paying customer?
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function is_paying_customer( $user_id ) {
|
2014-04-04 13:23:15 +00:00
|
|
|
return '1' === get_user_meta( $user_id, 'paying_customer', true );
|
2014-04-04 07:38:56 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is customer VAT exempt?
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function is_vat_exempt() {
|
2013-01-12 13:02:47 +00:00
|
|
|
return ( ! empty( $this->is_vat_exempt ) ) ? true : false;
|
2011-09-14 14:55:03 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the state from the current session.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_state() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->state;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the country from the current session
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_country() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->country;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the postcode from the current session.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_postcode() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return empty( $this->postcode ) ? '' : wc_format_postcode( $this->postcode, $this->get_country() );
|
2012-09-23 16:16:39 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-09-23 16:16:39 +00:00
|
|
|
/**
|
|
|
|
* Get the city from the current session.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return string
|
2012-09-23 16:16:39 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_city() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->city;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-11-27 01:56:48 +00:00
|
|
|
/**
|
|
|
|
* Gets the address from the current session.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return string
|
2012-11-27 01:56:48 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_address() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->address;
|
2012-11-27 01:56:48 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-11-27 01:56:48 +00:00
|
|
|
/**
|
|
|
|
* Gets the address_2 from the current session.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return string
|
2012-11-27 01:56:48 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_address_2() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->address_2;
|
2012-11-27 01:56:48 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the state from the current session.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_shipping_state() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->shipping_state;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the country from the current session.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_shipping_country() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->shipping_country;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the postcode from the current session.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_shipping_postcode() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return empty( $this->shipping_postcode ) ? '' : wc_format_postcode( $this->shipping_postcode, $this->get_shipping_country() );
|
2012-09-23 16:16:39 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
|
|
|
|
2012-09-23 16:16:39 +00:00
|
|
|
/**
|
|
|
|
* Gets the city from the current session.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return string
|
2012-09-23 16:16:39 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_shipping_city() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->shipping_city;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-11-27 01:56:48 +00:00
|
|
|
/**
|
|
|
|
* Gets the address from the current session.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return string
|
2012-11-27 01:56:48 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_shipping_address() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->shipping_address;
|
2012-11-27 01:56:48 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-11-27 01:56:48 +00:00
|
|
|
/**
|
|
|
|
* Gets the address_2 from the current session.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return string
|
2012-11-27 01:56:48 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_shipping_address_2() {
|
2014-05-15 12:27:13 +00:00
|
|
|
return $this->shipping_address_2;
|
2012-11-27 01:56:48 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-01 09:45:07 +00:00
|
|
|
/**
|
|
|
|
* get_taxable_address function.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return array
|
2012-10-01 09:45:07 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_taxable_address() {
|
2012-12-03 15:13:59 +00:00
|
|
|
$tax_based_on = get_option( 'woocommerce_tax_based_on' );
|
|
|
|
|
2013-09-03 15:26:02 +00:00
|
|
|
// Check shipping method at this point to see if we need special handling
|
2014-11-18 14:32:48 +00:00
|
|
|
if ( true == apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true ) && WC()->cart->needs_shipping() && sizeof( array_intersect( WC()->session->get( 'chosen_shipping_methods', array( get_option( 'woocommerce_default_shipping_method' ) ) ), apply_filters( 'woocommerce_local_pickup_methods', array( 'local_pickup' ) ) ) ) > 0 ) {
|
2013-09-03 15:26:02 +00:00
|
|
|
$tax_based_on = 'base';
|
|
|
|
}
|
|
|
|
|
2012-12-03 15:13:59 +00:00
|
|
|
if ( $tax_based_on == 'base' ) {
|
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
$default = $this->get_default_location();
|
2012-12-03 15:13:59 +00:00
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
$country = $default['country'];
|
|
|
|
$state = $default['state'];
|
|
|
|
$postcode = '';
|
|
|
|
$city = '';
|
2012-12-03 15:13:59 +00:00
|
|
|
|
|
|
|
} elseif ( $tax_based_on == 'billing' ) {
|
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
$country = $this->get_country();
|
|
|
|
$state = $this->get_state();
|
|
|
|
$postcode = $this->get_postcode();
|
|
|
|
$city = $this->get_city();
|
2012-12-03 15:13:59 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2014-11-18 14:32:48 +00:00
|
|
|
$country = $this->get_shipping_country();
|
|
|
|
$state = $this->get_shipping_state();
|
|
|
|
$postcode = $this->get_shipping_postcode();
|
|
|
|
$city = $this->get_shipping_city();
|
2012-12-03 15:13:59 +00:00
|
|
|
|
2012-10-01 09:45:07 +00:00
|
|
|
}
|
2012-12-03 15:13:59 +00:00
|
|
|
|
2012-10-01 09:45:07 +00:00
|
|
|
return apply_filters( 'woocommerce_customer_taxable_address', array( $country, $state, $postcode, $city ) );
|
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Sets session data for the location.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2014-09-07 23:37:55 +00:00
|
|
|
* @param string $country
|
|
|
|
* @param string $state
|
2012-08-14 19:42:38 +00:00
|
|
|
* @param string $postcode (default: '')
|
2012-09-23 16:16:39 +00:00
|
|
|
* @param string $city (default: '')
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_location( $country, $state, $postcode = '', $city = '' ) {
|
2014-05-15 12:27:13 +00:00
|
|
|
$this->country = $country;
|
|
|
|
$this->state = $state;
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->postcode = $postcode;
|
2014-05-15 12:27:13 +00:00
|
|
|
$this->city = $city;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the country.
|
|
|
|
*
|
|
|
|
* @param mixed $country
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_country( $country ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->country = $country;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the state.
|
|
|
|
*
|
|
|
|
* @param mixed $state
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_state( $state ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->state = $state;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the postcode.
|
|
|
|
*
|
|
|
|
* @param mixed $postcode
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_postcode( $postcode ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->postcode = $postcode;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-09-23 16:16:39 +00:00
|
|
|
/**
|
|
|
|
* Sets session data for the city.
|
|
|
|
*
|
2014-09-02 19:50:19 +00:00
|
|
|
* @param mixed $city
|
2012-09-23 16:16:39 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_city( $city ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->city = $city;
|
2012-09-23 16:16:39 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 01:56:48 +00:00
|
|
|
/**
|
|
|
|
* Sets session data for the address.
|
|
|
|
*
|
|
|
|
* @param mixed $address
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_address( $address ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->address = $address;
|
2012-11-27 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the address_2.
|
|
|
|
*
|
|
|
|
* @param mixed $address_2
|
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_address_2( $address_2 ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->address_2 = $address_2;
|
2012-11-27 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Sets session data for the location.
|
|
|
|
*
|
2014-09-07 23:37:55 +00:00
|
|
|
* @param string $country
|
2012-08-14 19:42:38 +00:00
|
|
|
* @param string $state (default: '')
|
|
|
|
* @param string $postcode (default: '')
|
2012-11-27 16:22:47 +00:00
|
|
|
* @param string $city (default: '')
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_shipping_location( $country, $state = '', $postcode = '', $city = '' ) {
|
2014-05-15 12:27:13 +00:00
|
|
|
$this->shipping_country = $country;
|
|
|
|
$this->shipping_state = $state;
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->shipping_postcode = $postcode;
|
2014-05-15 12:27:13 +00:00
|
|
|
$this->shipping_city = $city;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the country.
|
|
|
|
*
|
2014-05-15 12:27:13 +00:00
|
|
|
* @param string $country
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_shipping_country( $country ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->shipping_country = $country;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the state.
|
|
|
|
*
|
2014-05-15 12:27:13 +00:00
|
|
|
* @param string $state
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_shipping_state( $state ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->shipping_state = $state;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the postcode.
|
|
|
|
*
|
2014-05-15 12:27:13 +00:00
|
|
|
* @param string $postcode
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_shipping_postcode( $postcode ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->shipping_postcode = $postcode;
|
2012-09-23 16:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the city.
|
|
|
|
*
|
2014-09-02 19:50:19 +00:00
|
|
|
* @param string $city
|
2012-09-23 16:16:39 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_shipping_city( $city ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->shipping_city = $city;
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-11-27 01:56:48 +00:00
|
|
|
/**
|
|
|
|
* Sets session data for the address.
|
|
|
|
*
|
2014-05-15 12:27:13 +00:00
|
|
|
* @param string $address
|
2012-11-27 01:56:48 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_shipping_address( $address ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->shipping_address = $address;
|
2012-11-27 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets session data for the address_2.
|
|
|
|
*
|
2014-05-15 12:27:13 +00:00
|
|
|
* @param string $address_2
|
2012-11-27 01:56:48 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_shipping_address_2( $address_2 ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->shipping_address_2 = $address_2;
|
2012-11-27 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Sets session data for the tax exemption.
|
|
|
|
*
|
2014-05-15 12:27:13 +00:00
|
|
|
* @param bool $is_vat_exempt
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function set_is_vat_exempt( $is_vat_exempt ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->is_vat_exempt = $is_vat_exempt;
|
2011-09-14 14:55:03 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-09-07 18:28:27 +00:00
|
|
|
/**
|
|
|
|
* calculated_shipping function.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2014-09-07 23:37:55 +00:00
|
|
|
* @param boolean $calculated
|
2012-09-07 18:28:27 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function calculated_shipping( $calculated = true ) {
|
2013-01-12 13:02:47 +00:00
|
|
|
$this->calculated_shipping = $calculated;
|
2012-09-07 18:28:27 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
/**
|
2012-08-14 19:42:38 +00:00
|
|
|
* Gets a user's downloadable products if they are logged in.
|
2011-08-09 15:16:18 +00:00
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return array Array of downloadable products
|
2011-08-09 15:16:18 +00:00
|
|
|
*/
|
2012-12-14 21:43:45 +00:00
|
|
|
public function get_downloadable_products() {
|
2014-05-28 17:05:19 +00:00
|
|
|
$downloads = array();
|
2014-02-17 11:58:14 +00:00
|
|
|
|
|
|
|
if ( is_user_logged_in() ) {
|
2014-05-28 17:05:19 +00:00
|
|
|
$downloads = wc_get_customer_available_downloads( get_current_user_id() );
|
2014-02-17 11:58:14 +00:00
|
|
|
}
|
2012-08-28 15:21:54 +00:00
|
|
|
|
2014-02-17 11:58:14 +00:00
|
|
|
return apply_filters( 'woocommerce_customer_get_downloadable_products', $downloads );
|
2012-08-14 19:42:38 +00:00
|
|
|
}
|
2014-05-28 17:05:19 +00:00
|
|
|
}
|