Store custom checkout fields prefixed with shipping or billing in meta

Closes #12634
This commit is contained in:
Mike Jolley 2016-12-19 14:51:56 +00:00
parent 218689d9c3
commit 910d6d9900
2 changed files with 14 additions and 2 deletions

View File

@ -288,8 +288,13 @@ class WC_Checkout {
} }
foreach ( $data as $key => $value ) { foreach ( $data as $key => $value ) {
// Use setters where available.
if ( is_callable( array( $order, "set_{$key}" ) ) ) { if ( is_callable( array( $order, "set_{$key}" ) ) ) {
$order->{"set_{$key}"}( $value ); $order->{"set_{$key}"}( $value );
// Store custom fields prefixed with wither shipping_ or billing_. This is for backwards compatibility with 2.6.x.
} elseif ( 0 === stripos( $key, 'billing_' ) || 0 === stripos( $key, 'shipping_' ) ) {
$order->update_meta_data( '_' . $key, $value );
} }
} }
@ -811,8 +816,13 @@ class WC_Checkout {
$customer->set_last_name( $data['billing_last_name'] ); $customer->set_last_name( $data['billing_last_name'] );
foreach ( $data as $key => $value ) { foreach ( $data as $key => $value ) {
// Use setters where available.
if ( is_callable( array( $customer, "set_{$key}" ) ) ) { if ( is_callable( array( $customer, "set_{$key}" ) ) ) {
$customer->{"set_{$key}"}( $value ); $customer->{"set_{$key}"}( $value );
// Store custom fields prefixed with wither shipping_ or billing_.
} elseif ( 0 === stripos( $key, 'billing_' ) || 0 === stripos( $key, 'shipping_' ) ) {
$customer->update_meta_data( $key, $value );
} }
} }
$customer->save(); $customer->save();
@ -923,7 +933,7 @@ class WC_Checkout {
* Gets the value either from the posted data, or from the users meta data. * Gets the value either from the posted data, or from the users meta data.
* *
* @param string $input * @param string $input
* @return string|null * @return string
*/ */
public function get_value( $input ) { public function get_value( $input ) {
if ( ! empty( $_POST[ $input ] ) ) { if ( ! empty( $_POST[ $input ] ) ) {
@ -937,7 +947,7 @@ class WC_Checkout {
if ( is_callable( array( WC()->customer, "get_$input" ) ) ) { if ( is_callable( array( WC()->customer, "get_$input" ) ) ) {
$value = WC()->customer->{"get_$input"}(); $value = WC()->customer->{"get_$input"}();
} else { } else {
$value = null; $value = WC()->customer->get_meta( $input, true );
} }
return apply_filters( 'default_checkout_' . $input, $value, $input ); return apply_filters( 'default_checkout_' . $input, $value, $input );

View File

@ -64,6 +64,8 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
'_payment_tokens', '_payment_tokens',
'_billing_address_index', '_billing_address_index',
'_shipping_address_index', '_shipping_address_index',
'_recorded_sales',
'_shipping_method',
); );
/** /**