save addresses

This commit is contained in:
Mike Jolley 2016-11-17 15:32:52 +00:00
parent d88b512143
commit 717f712b3d
3 changed files with 95 additions and 54 deletions

View File

@ -1510,7 +1510,7 @@ class WC_Order extends WC_Abstract_Order {
* @return string * @return string
*/ */
public function get_total_refunded() { public function get_total_refunded() {
return $this->data_store->get_total_refunded(); return $this->data_store->get_total_refunded( $this );
} }
/** /**
@ -1520,7 +1520,7 @@ class WC_Order extends WC_Abstract_Order {
* @return float * @return float
*/ */
public function get_total_tax_refunded() { public function get_total_tax_refunded() {
return $this->data_store->get_total_tax_refunded(); return $this->data_store->get_total_tax_refunded( $this );
} }
/** /**
@ -1530,7 +1530,7 @@ class WC_Order extends WC_Abstract_Order {
* @return float * @return float
*/ */
public function get_total_shipping_refunded() { public function get_total_shipping_refunded() {
return $this->data_store->get_total_shipping_refunded(); return $this->data_store->get_total_shipping_refunded( $this );
} }
/** /**

View File

@ -127,30 +127,50 @@ class WC_Customer_Data_Store implements WC_Customer_Data_Store_Interface, WC_Obj
} }
} }
if ( in_array( 'billing', $changed_props ) ) { $billing_address_props = array(
update_user_meta( $customer->get_id(), 'billing_first_name', $customer->get_billing_first_name( 'edit' ) ); 'billing_first_name' => 'billing_first_name',
update_user_meta( $customer->get_id(), 'billing_last_name', $customer->get_billing_last_name( 'edit' ) ); 'billing_last_name' => 'billing_last_name',
update_user_meta( $customer->get_id(), 'billing_company', $customer->get_billing_company( 'edit' ) ); 'billing_company' => 'billing_company',
update_user_meta( $customer->get_id(), 'billing_phone', $customer->get_billing_phone( 'edit' ) ); 'billing_address_1' => 'billing_address_1',
update_user_meta( $customer->get_id(), 'billing_email', $customer->get_billing_email( 'edit' ) ); 'billing_address_2' => 'billing_address_2',
update_user_meta( $customer->get_id(), 'billing_postcode', $customer->get_billing_postcode( 'edit' ) ); 'billing_city' => 'billing_city',
update_user_meta( $customer->get_id(), 'billing_city', $customer->get_billing_city( 'edit' ) ); 'billing_state' => 'billing_state',
update_user_meta( $customer->get_id(), 'billing_address_1', $customer->get_billing_address( 'edit' ) ); 'billing_postcode' => 'billing_postcode',
update_user_meta( $customer->get_id(), 'billing_address_2', $customer->get_billing_address_2( 'edit' ) ); 'billing_country' => 'billing_country',
update_user_meta( $customer->get_id(), 'billing_state', $customer->get_billing_state( 'edit' ) ); 'billing_email' => 'billing_email',
update_user_meta( $customer->get_id(), 'billing_country', $customer->get_billing_country( 'edit' ) ); 'billing_phone' => 'billing_phone',
);
foreach ( $billing_address_props as $meta_key => $prop ) {
$prop_key = substr( $prop, 8 );
if ( ! isset( $changed_props['billing'] ) || ! in_array( $prop_key, $changed_props['billing'] ) ) {
continue;
}
if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
$updated_props[] = $prop;
}
} }
if ( in_array( 'shipping', $changed_props ) ) { $shipping_address_props = array(
update_user_meta( $customer->get_id(), 'shipping_first_name', $customer->get_shipping_first_name( 'edit' ) ); 'shipping_first_name' => 'shipping_first_name',
update_user_meta( $customer->get_id(), 'shipping_last_name', $customer->get_shipping_last_name( 'edit' ) ); 'shipping_last_name' => 'shipping_last_name',
update_user_meta( $customer->get_id(), 'shipping_company', $customer->get_shipping_company( 'edit' ) ); 'shipping_company' => 'shipping_company',
update_user_meta( $customer->get_id(), 'shipping_postcode', $customer->get_shipping_postcode( 'edit' ) ); 'shipping_address_1' => 'shipping_address_1',
update_user_meta( $customer->get_id(), 'shipping_city', $customer->get_shipping_city( 'edit' ) ); 'shipping_address_2' => 'shipping_address_2',
update_user_meta( $customer->get_id(), 'shipping_address_1', $customer->get_shipping_address( 'edit' ) ); 'shipping_city' => 'shipping_city',
update_user_meta( $customer->get_id(), 'shipping_address_2', $customer->get_shipping_address_2( 'edit' ) ); 'shipping_state' => 'shipping_state',
update_user_meta( $customer->get_id(), 'shipping_state', $customer->get_shipping_state( 'edit' ) ); 'shipping_postcode' => 'shipping_postcode',
update_user_meta( $customer->get_id(), 'shipping_country', $customer->get_shipping_country( 'edit' ) ); 'shipping_country' => 'shipping_country',
);
foreach ( $shipping_address_props as $meta_key => $prop ) {
$prop_key = substr( $prop, 9 );
if ( ! isset( $changed_props['shipping'] ) || ! in_array( $prop_key, $changed_props['shipping'] ) ) {
continue;
}
if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
$updated_props[] = $prop;
}
} }
} }

View File

@ -82,26 +82,6 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
$meta_key_to_props = array( $meta_key_to_props = array(
'_order_key' => 'order_key', '_order_key' => 'order_key',
'_customer_user' => 'customer_user', '_customer_user' => 'customer_user',
'_billing_first_name' => 'billing_first_name',
'_billing_last_name' => 'billing_last_name',
'_billing_company' => 'billing_company',
'_billing_address_1' => 'billing_address_1',
'_billing_address_2' => 'billing_address_2',
'_billing_city' => 'billing_city',
'_billing_state' => 'billing_state',
'_billing_postcode' => 'billing_postcode',
'_billing_country' => 'billing_country',
'_billing_email' => 'billing_email',
'_billing_phone' => 'billing_phone',
'_shipping_first_name' => 'shipping_first_name',
'_shipping_last_name' => 'shipping_last_name',
'_shipping_company' => 'shipping_company',
'_shipping_address_1' => 'shipping_address_1',
'_shipping_address_2' => 'shipping_address_2',
'_shipping_city' => 'shipping_city',
'_shipping_state' => 'shipping_state',
'_shipping_postcode' => 'shipping_postcode',
'_shipping_country' => 'shipping_country',
'_payment_method' => 'payment_method', '_payment_method' => 'payment_method',
'_payment_method_title' => 'payment_method_title', '_payment_method_title' => 'payment_method_title',
'_transaction_id' => 'transaction_id', '_transaction_id' => 'transaction_id',
@ -113,23 +93,64 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
'_date_paid' => 'date_paid', '_date_paid' => 'date_paid',
'_cart_hash' => 'cart_hash', '_cart_hash' => 'cart_hash',
); );
foreach ( $meta_key_to_props as $meta_key => $prop ) { foreach ( $meta_key_to_props as $meta_key => $prop ) {
// ADDRESSES @todo
if ( ! in_array( $prop, $changed_props ) ) { if ( ! in_array( $prop, $changed_props ) ) {
continue; continue;
} }
$value = $order->{"get_$prop"}( 'edit' ); $value = $order->{"get_$prop"}( 'edit' );
if ( '' !== $value ) { if ( '' !== $value ? update_post_meta( $order->get_id(), $meta_key, $value ) : delete_post_meta( $order->get_id(), $meta_key ) ) {
$updated = update_post_meta( $order->get_id(), $meta_key, $value ); $updated_props[] = $prop;
} else {
$updated = delete_post_meta( $order->get_id(), $meta_key );
} }
}
if ( $updated ) { $billing_address_props = array(
'_billing_first_name' => 'billing_first_name',
'_billing_last_name' => 'billing_last_name',
'_billing_company' => 'billing_company',
'_billing_address_1' => 'billing_address_1',
'_billing_address_2' => 'billing_address_2',
'_billing_city' => 'billing_city',
'_billing_state' => 'billing_state',
'_billing_postcode' => 'billing_postcode',
'_billing_country' => 'billing_country',
'_billing_email' => 'billing_email',
'_billing_phone' => 'billing_phone',
);
foreach ( $billing_address_props as $meta_key => $prop ) {
$prop_key = substr( $prop, 8 );
if ( ! isset( $changed_props['billing'] ) || ! in_array( $prop_key, $changed_props['billing'] ) ) {
continue;
}
$value = $order->{"get_$prop"}( 'edit' );
if ( '' !== $value ? update_post_meta( $order->get_id(), $meta_key, $value ) : delete_post_meta( $order->get_id(), $meta_key ) ) {
$updated_props[] = $prop;
}
}
$shipping_address_props = array(
'_shipping_first_name' => 'shipping_first_name',
'_shipping_last_name' => 'shipping_last_name',
'_shipping_company' => 'shipping_company',
'_shipping_address_1' => 'shipping_address_1',
'_shipping_address_2' => 'shipping_address_2',
'_shipping_city' => 'shipping_city',
'_shipping_state' => 'shipping_state',
'_shipping_postcode' => 'shipping_postcode',
'_shipping_country' => 'shipping_country',
);
foreach ( $shipping_address_props as $meta_key => $prop ) {
$prop_key = substr( $prop, 9 );
if ( ! isset( $changed_props['shipping'] ) || ! in_array( $prop_key, $changed_props['shipping'] ) ) {
continue;
}
$value = $order->{"get_$prop"}( 'edit' );
if ( '' !== $value ? update_post_meta( $order->get_id(), $meta_key, $value ) : delete_post_meta( $order->get_id(), $meta_key ) ) {
$updated_props[] = $prop; $updated_props[] = $prop;
} }
} }