Skip to content

Instantly share code, notes, and snippets.

@leup
Created April 19, 2018 12:08
Show Gist options
  • Save leup/c35c0930b13d18697d266fa7a4f6d3b9 to your computer and use it in GitHub Desktop.
Save leup/c35c0930b13d18697d266fa7a4f6d3b9 to your computer and use it in GitHub Desktop.
<?php
function laf_woocommerce_checkout_update_order_review($post_data)
{
if (!empty($post_data)) {
parse_str($post_data, $data);
}
else
return false;
WC()->customer->set_props( array(
'billing_first_name' => isset( $data['billing_first_name'] ) ? wp_unslash( $data['billing_first_name'] ) : null,
'billing_last_name' => isset( $data['billing_last_name'] ) ? wp_unslash( $data['billing_last_name'] ) : null,
'billing_company' => isset( $data['billing_company'] ) ? wp_unslash( $data['billing_company'] ) : null,
'billing_phone' => isset( $data['billing_phone'] ) ? wp_unslash( $data['billing_phone'] ) : null,
'billing_email' => isset( $data['billing_email'] ) ? wp_unslash( $data['billing_email'] ) : null
) );
if ( wc_ship_to_billing_address_only() ) {
WC()->customer->set_props( array(
'shipping_first_name' => isset( $data['billing_first_name'] ) ? wp_unslash( $data['billing_first_name'] ) : null,
'shipping_last_name' => isset( $data['billing_last_name'] ) ? wp_unslash( $data['billing_last_name'] ) : null,
'shipping_company' => isset( $data['billing_company'] ) ? wp_unslash( $data['billing_company'] ) : null,
'shipping_phone' => isset( $data['billing_phone'] ) ? wp_unslash( $data['billing_phone'] ) : null,
'shipping_email' => isset( $data['billing_email'] ) ? wp_unslash( $data['billing_email'] ) : null
) );
} else {
WC()->customer->set_props( array(
'shipping_first_name' => isset( $data['shipping_first_name'] ) ? wp_unslash( $data['shipping_first_name'] ) : null,
'shipping_last_name' => isset( $data['shipping_last_name'] ) ? wp_unslash( $data['shipping_last_name'] ) : null,
'shipping_company' => isset( $data['shipping_company'] ) ? wp_unslash( $data['shipping_company'] ) : null,
'shipping_phone' => isset( $data['shipping_phone'] ) ? wp_unslash( $data['billing_phone'] ) : null,
'shipping_email' => isset( $data['shipping_email'] ) ? wp_unslash( $data['shipping_email'] ) : null
) );
}
}
add_action('woocommerce_checkout_update_order_review', 'laf_woocommerce_checkout_update_order_review');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment