Fix save
This commit is contained in:
parent
717f712b3d
commit
8d6f236d47
|
@ -491,6 +491,7 @@ abstract class WC_Data {
|
|||
/**
|
||||
* Set a collection of props in one go, collect any errors, and return the result.
|
||||
* Only sets using public methods.
|
||||
*
|
||||
* @param array $props Key value pairs to set. Key is the prop and should map to a setter function name.
|
||||
* @return WP_Error|bool
|
||||
*/
|
||||
|
|
|
@ -101,6 +101,13 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
*/
|
||||
protected $cache_group = 'order';
|
||||
|
||||
/**
|
||||
* Which data store to load.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $data_store_name = 'order';
|
||||
|
||||
/**
|
||||
* Get the order if ID is passed, otherwise the order is new and empty.
|
||||
* This class should NOT be instantiated, but the get_order function or new WC_Order_Factory.
|
||||
|
@ -127,7 +134,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
$this->set_status( apply_filters( 'woocommerce_default_order_status', 'pending' ) );
|
||||
}
|
||||
|
||||
$this->data_store = WC_Data_Store::load( 'order_' . $this->get_type() );
|
||||
$this->data_store = WC_Data_Store::load( $this->data_store_name );
|
||||
|
||||
if ( $this->get_id() > 0 ) {
|
||||
$this->data_store->read( $this );
|
||||
}
|
||||
|
|
|
@ -882,7 +882,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
protected function set_address_prop( $prop, $address = 'billing', $value ) {
|
||||
if ( array_key_exists( $prop, $this->data[ $address ] ) ) {
|
||||
if ( true === $this->object_read ) {
|
||||
if ( $value !== $this->data[ $address ][ $prop ] || array_key_exists( $prop, $this->changes[ $address ] ) ) {
|
||||
if ( $value !== $this->data[ $address ][ $prop ] || ( isset( $this->changes[ $address ] ) && array_key_exists( $prop, $this->changes[ $address ] ) ) ) {
|
||||
$this->changes[ $address ][ $prop ] = $value;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -831,6 +831,26 @@ class WC_Order extends WC_Abstract_Order {
|
|||
|
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets a prop for a setter method.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $prop Name of prop to set.
|
||||
* @param string $address Name of address to set. billing or shipping.
|
||||
* @param mixed $value Value of the prop.
|
||||
*/
|
||||
protected function set_address_prop( $prop, $address = 'billing', $value ) {
|
||||
if ( array_key_exists( $prop, $this->data[ $address ] ) ) {
|
||||
if ( true === $this->object_read ) {
|
||||
if ( $value !== $this->data[ $address ][ $prop ] || ( isset( $this->changes[ $address ] ) && array_key_exists( $prop, $this->changes[ $address ] ) ) ) {
|
||||
$this->changes[ $address ][ $prop ] = $value;
|
||||
}
|
||||
} else {
|
||||
$this->data[ $address ][ $prop ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order_key.
|
||||
*
|
||||
|
@ -851,26 +871,6 @@ class WC_Order extends WC_Abstract_Order {
|
|||
$this->set_prop( 'customer_id', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a prop for a setter method.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $prop Name of prop to set.
|
||||
* @param string $address Name of address to set. billing or shipping.
|
||||
* @param mixed $value Value of the prop.
|
||||
*/
|
||||
protected function set_address_prop( $prop, $address = 'billing', $value ) {
|
||||
if ( array_key_exists( $prop, $this->data[ $address ] ) ) {
|
||||
if ( true === $this->object_read ) {
|
||||
if ( $value !== $this->data[ $address ][ $prop ] || array_key_exists( $prop, $this->changes[ $address ] ) ) {
|
||||
$this->changes[ $address ][ $prop ] = $value;
|
||||
}
|
||||
} else {
|
||||
$this->data[ $address ][ $prop ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_first_name.
|
||||
*
|
||||
|
|
|
@ -40,7 +40,6 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_CPT implem
|
|||
|
||||
if ( $id && ! is_wp_error( $id ) ) {
|
||||
$order->set_id( $id );
|
||||
$this->save_items( $order );
|
||||
$this->update_post_meta( $order );
|
||||
$order->save_meta_data();
|
||||
$order->apply_changes();
|
||||
|
@ -86,7 +85,6 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_CPT implem
|
|||
'post_parent' => $order->get_parent_id(),
|
||||
) );
|
||||
|
||||
$this->save_items( $order );
|
||||
$this->update_post_meta( $order );
|
||||
$order->save_meta_data();
|
||||
$order->apply_changes();
|
||||
|
|
|
@ -109,7 +109,7 @@ class WC_Customer_Data_Store implements WC_Customer_Data_Store_Interface, WC_Obj
|
|||
*/
|
||||
private function update_user_meta( $customer ) {
|
||||
$updated_props = array();
|
||||
$changed_props = array_keys( $customer->get_changes() );
|
||||
$changed_props = $customer->get_changes();
|
||||
|
||||
$meta_key_to_props = array(
|
||||
'paying_customer' => 'is_paying_customer',
|
||||
|
@ -118,7 +118,7 @@ class WC_Customer_Data_Store implements WC_Customer_Data_Store_Interface, WC_Obj
|
|||
);
|
||||
|
||||
foreach ( $meta_key_to_props as $meta_key => $prop ) {
|
||||
if ( ! in_array( $prop, $changed_props ) ) {
|
||||
if ( ! array_key_exists( $prop, $changed_props ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ class WC_Customer_Data_Store implements WC_Customer_Data_Store_Interface, WC_Obj
|
|||
|
||||
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'] ) ) {
|
||||
if ( ! isset( $changed_props['billing'] ) || ! array_key_exists( $prop_key, $changed_props['billing'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
|
||||
|
@ -165,7 +165,7 @@ class WC_Customer_Data_Store implements WC_Customer_Data_Store_Interface, WC_Obj
|
|||
|
||||
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'] ) ) {
|
||||
if ( ! isset( $changed_props['shipping'] ) || ! array_key_exists( $prop_key, $changed_props['shipping'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
|
||||
|
|
|
@ -78,7 +78,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
*/
|
||||
protected function update_post_meta( &$order ) {
|
||||
$updated_props = array();
|
||||
$changed_props = array_keys( $order->get_changes() );
|
||||
$changed_props = $order->get_changes();
|
||||
$meta_key_to_props = array(
|
||||
'_order_key' => 'order_key',
|
||||
'_customer_user' => 'customer_user',
|
||||
|
@ -95,7 +95,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
);
|
||||
|
||||
foreach ( $meta_key_to_props as $meta_key => $prop ) {
|
||||
if ( ! in_array( $prop, $changed_props ) ) {
|
||||
if ( ! array_key_exists( $prop, $changed_props ) ) {
|
||||
continue;
|
||||
}
|
||||
$value = $order->{"get_$prop"}( 'edit' );
|
||||
|
@ -121,7 +121,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
|
||||
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'] ) ) {
|
||||
if ( ! isset( $changed_props['billing'] ) || ! array_key_exists( $prop_key, $changed_props['billing'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$value = $order->{"get_$prop"}( 'edit' );
|
||||
|
@ -145,7 +145,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
|
||||
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'] ) ) {
|
||||
if ( ! isset( $changed_props['shipping'] ) || ! array_key_exists( $prop_key, $changed_props['shipping'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$value = $order->{"get_$prop"}( 'edit' );
|
||||
|
|
Loading…
Reference in New Issue