getters
This commit is contained in:
parent
52c866c57b
commit
87aadaa7cf
|
@ -581,7 +581,7 @@ abstract class WC_Data {
|
||||||
* @param string $context What the value is for. Valid values are view and edit.
|
* @param string $context What the value is for. Valid values are view and edit.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get_prop( $prop, $context = 'view' ) {
|
protected function get_prop( $prop, $context = 'view' ) {
|
||||||
$value = null;
|
$value = null;
|
||||||
|
|
||||||
if ( array_key_exists( $prop, $this->data ) ) {
|
if ( array_key_exists( $prop, $this->data ) ) {
|
||||||
|
|
|
@ -396,269 +396,345 @@ class WC_Order extends WC_Abstract_Order {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get order key.
|
* Get order key.
|
||||||
|
*
|
||||||
* @since 2.7.0
|
* @since 2.7.0
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_order_key() {
|
public function get_order_key( $context = 'view' ) {
|
||||||
return $this->data['order_key'];
|
return $this->get_prop( 'order_key', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get customer_id
|
* Get customer_id.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function get_customer_id() {
|
public function get_customer_id( $context = 'view' ) {
|
||||||
return $this->data['customer_id'];
|
return $this->get_prop( 'customer_id', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias for get_customer_id().
|
* Alias for get_customer_id().
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function get_user_id() {
|
public function get_user_id( $context = 'view' ) {
|
||||||
return $this->get_customer_id();
|
return $this->get_customer_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user associated with the order. False for guests.
|
* Get the user associated with the order. False for guests.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return WP_User|false
|
* @return WP_User|false
|
||||||
*/
|
*/
|
||||||
public function get_user() {
|
public function get_user( $context = 'view' ) {
|
||||||
return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
|
return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_first_name
|
* Get billing_first_name.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_first_name() {
|
public function get_billing_first_name( $context = 'view' ) {
|
||||||
return $this->data['billing']['first_name'];
|
return $this->get_prop( 'billing']['first_name', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_last_name
|
* Get billing_last_name.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_last_name() {
|
public function get_billing_last_name( $context = 'view' ) {
|
||||||
return $this->data['billing']['last_name'];
|
return $this->get_prop( 'billing']['last_name', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_company
|
* Get billing_company.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_company() {
|
public function get_billing_company( $context = 'view' ) {
|
||||||
return $this->data['billing']['company'];
|
return $this->get_prop( 'billing']['company', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_address_1
|
* Get billing_address_1.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_address_1() {
|
public function get_billing_address_1( $context = 'view' ) {
|
||||||
return $this->data['billing']['address_1'];
|
return $this->get_prop( 'billing']['address_1', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_address_2
|
* Get billing_address_2.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string $value
|
* @return string $value
|
||||||
*/
|
*/
|
||||||
public function get_billing_address_2() {
|
public function get_billing_address_2( $context = 'view' ) {
|
||||||
return $this->data['billing']['address_2'];
|
return $this->get_prop( 'billing']['address_2', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_city
|
* Get billing_city.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string $value
|
* @return string $value
|
||||||
*/
|
*/
|
||||||
public function get_billing_city() {
|
public function get_billing_city( $context = 'view' ) {
|
||||||
return $this->data['billing']['city'];
|
return $this->get_prop( 'billing']['city', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_state
|
* Get billing_state.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_state() {
|
public function get_billing_state( $context = 'view' ) {
|
||||||
return $this->data['billing']['state'];
|
return $this->get_prop( 'billing']['state', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_postcode
|
* Get billing_postcode.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_postcode() {
|
public function get_billing_postcode( $context = 'view' ) {
|
||||||
return $this->data['billing']['postcode'];
|
return $this->get_prop( 'billing']['postcode', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_country
|
* Get billing_country.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_country() {
|
public function get_billing_country( $context = 'view' ) {
|
||||||
return $this->data['billing']['country'];
|
return $this->get_prop( 'billing']['country', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_email
|
* Get billing_email.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_email() {
|
public function get_billing_email( $context = 'view' ) {
|
||||||
return $this->data['billing']['email'];
|
return $this->get_prop( 'billing']['email', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing_phone
|
* Get billing_phone.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_billing_phone() {
|
public function get_billing_phone( $context = 'view' ) {
|
||||||
return $this->data['billing']['phone'];
|
return $this->get_prop( 'billing']['phone', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_first_name
|
* Get shipping_first_name.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_first_name() {
|
public function get_shipping_first_name( $context = 'view' ) {
|
||||||
return $this->data['shipping']['first_name'];
|
return $this->get_prop( 'shipping']['first_name', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_last_name
|
* Get shipping_last_name.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_last_name() {
|
public function get_shipping_last_name( $context = 'view' ) {
|
||||||
return $this->data['shipping']['last_name'];
|
return $this->get_prop( 'shipping']['last_name', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_company
|
* Get shipping_company.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_company() {
|
public function get_shipping_company( $context = 'view' ) {
|
||||||
return $this->data['shipping']['company'];
|
return $this->get_prop( 'shipping']['company', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_address_1
|
* Get shipping_address_1.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_address_1() {
|
public function get_shipping_address_1( $context = 'view' ) {
|
||||||
return $this->data['shipping']['address_1'];
|
return $this->get_prop( 'shipping']['address_1', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_address_2
|
* Get shipping_address_2.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_address_2() {
|
public function get_shipping_address_2( $context = 'view' ) {
|
||||||
return $this->data['shipping']['address_2'];
|
return $this->get_prop( 'shipping']['address_2', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_city
|
* Get shipping_city.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_city() {
|
public function get_shipping_city( $context = 'view' ) {
|
||||||
return $this->data['shipping']['city'];
|
return $this->get_prop( 'shipping']['city', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_state
|
* Get shipping_state.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_state() {
|
public function get_shipping_state( $context = 'view' ) {
|
||||||
return $this->data['shipping']['state'];
|
return $this->get_prop( 'shipping']['state', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_postcode
|
* Get shipping_postcode.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_postcode() {
|
public function get_shipping_postcode( $context = 'view' ) {
|
||||||
return $this->data['shipping']['postcode'];
|
return $this->get_prop( 'shipping']['postcode', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shipping_country
|
* Get shipping_country.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_shipping_country() {
|
public function get_shipping_country( $context = 'view' ) {
|
||||||
return $this->data['shipping']['country'];
|
return $this->get_prop( 'shipping']['country', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the payment method.
|
* Get the payment method.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_payment_method() {
|
public function get_payment_method( $context = 'view' ) {
|
||||||
return $this->data['payment_method'];
|
return $this->get_prop( 'payment_method', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get payment_method_title
|
* Get payment_method_title.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_payment_method_title() {
|
public function get_payment_method_title( $context = 'view' ) {
|
||||||
return $this->data['payment_method_title'];
|
return $this->get_prop( 'payment_method_title', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get transaction_id
|
* Get transaction_id.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_transaction_id() {
|
public function get_transaction_id( $context = 'view' ) {
|
||||||
return $this->data['transaction_id'];
|
return $this->get_prop( 'transaction_id', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get customer_ip_address
|
* Get customer_ip_address.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_customer_ip_address() {
|
public function get_customer_ip_address( $context = 'view' ) {
|
||||||
return $this->data['customer_ip_address'];
|
return $this->get_prop( 'customer_ip_address', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get customer_user_agent
|
* Get customer_user_agent.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_customer_user_agent() {
|
public function get_customer_user_agent( $context = 'view' ) {
|
||||||
return $this->data['customer_user_agent'];
|
return $this->get_prop( 'customer_user_agent', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get created_via
|
* Get created_via.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_created_via() {
|
public function get_created_via( $context = 'view' ) {
|
||||||
return $this->data['created_via'];
|
return $this->get_prop( 'created_via', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get customer_note
|
* Get customer_note.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_customer_note() {
|
public function get_customer_note( $context = 'view' ) {
|
||||||
return $this->data['customer_note'];
|
return $this->get_prop( 'customer_note', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get date_completed
|
* Get date_completed.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function get_date_completed() {
|
public function get_date_completed( $context = 'view' ) {
|
||||||
return absint( $this->data['date_completed'] );
|
return absint( $this->data['date_completed'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get date_paid
|
* Get date_paid.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function get_date_paid() {
|
public function get_date_paid( $context = 'view' ) {
|
||||||
return absint( $this->data['date_paid'] );
|
return absint( $this->data['date_paid'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get cart hash.
|
||||||
|
*
|
||||||
|
* @param string $context
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_cart_hash( $context = 'view' ) {
|
||||||
|
return $this->get_prop( 'cart_hash', $context );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the requested address in raw, non-formatted way.
|
* Returns the requested address in raw, non-formatted way.
|
||||||
* @since 2.4.0
|
* @since 2.4.0
|
||||||
|
@ -717,14 +793,6 @@ class WC_Order extends WC_Abstract_Order {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get cart hash
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function get_cart_hash() {
|
|
||||||
return $this->data['cart_hash'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Setters
|
| Setters
|
||||||
|
|
Loading…
Reference in New Issue