How are you adding the custom field? If your custom code or the plugin you are using uses the 'woocommerce_billing_fields' or 'woocommerce_shipping_fields' filters to add the custom field to the WooCommerce Address fields then the plugin should handle managing that field in the address automatically for saving and updating addresses.
Hi Matt,
I have added the field with the following:
add_filter( ‘woocommerce_shipping_fields’, ‘misha_add_shipping_field’ );
function misha_add_shipping_field( $fields ) {
$fields[‘shipping_address_nickname_identifier’] = array(
‘label’ => ‘shipping_address_nickname_identifier’,
‘required’ => false,
‘class’ => array( ‘form-row-wide’, ‘my-custom-class’ ),
‘priority’ => -2,
‘placeholder’ => ‘shipping identifier’,
);
return $fields;
}
Hmm, that should work just fine. That is the same way we add the “Address nickname” field to the addresses in the plugin.
ok, it started working after renaming function, appreciate your time.
Do you know if Make Primary will call the Hook: woocommerce_after_save_address_validation.
It does not call that hook. No field validation is performed at that step since it is only swapping the addresses.
Addresses would have already been validated before saving the first time.
is there another hook or a way i can trigger a function upon make primary?
add_action( 'wp_ajax_wc_address_book_make_primary', 'your_function_name', 9 );
Is probably closest with the current code. That would trigger before the address swapping.
But we can add a new hook that is called after the swap happens in a future version of the plugin.