Update:
In your comment code link, there is some errors in your code:
- In your bones_add_field_and_reorder_fields function, you are unsetting billing and shipping company, but after few lines down, you are trying to set those values in:
$newfields['billing']['billing_company'] = $fields['billing']['billing_company'];
$newfields['shipping']['shipping_company'] = $fields['shipping']['shipping_company'];
And it's throwing some errors…
You should not unset 'billing_company'
and 'shipping_company'
.
- Everywhere you are using
$order->id
and it should be replaced by $order->get_id()
.
- I have tested everything with your updated code and my updated function below. It works…
Using a custom function hooked in woocommerce_checkout_update_order_meta
action hook, you will be able to merge the values.
add_action( 'woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta', 10, 2 );
function custom_checkout_field_update_order_meta( $order_id ) {
$separator = '. ';
$billing_address_1 = sanitize_text_field( $_POST['billing_address_1'] );
$billing_houseno = sanitize_text_field( $_POST['billing_houseno'] );
if( ! ( empty($billing_address_1) && empty($billing_houseno) ) )
update_post_meta( $order_id, '_billing_address_1', $billing_address_1 . $separator . $billing_houseno );
$shipping_address_1 = sanitize_text_field( $_POST['shipping_address_1'] );
$shipping_houseno = sanitize_text_field( $_POST['shipping_houseno'] );
if( ! ( empty($shipping_address_1) && empty($shipping_houseno) ) )
update_post_meta( $order_id, '_shipping_address_1', $shipping_address_1 . $separator . $shipping_houseno );
}
Code goes in function.php file of the active child theme (or active theme).
This time, this is tested and works.