We’ve already seen how to update user meta after a successful order, but this time our goal is to “correct” or “edit” a checkout field value after the order is placed.
You could for example add a phone number prefix if it’s not there, and by doing so, correct the phone number before sending it to your courier. Likewise, you could remove punctuation, trim spaces, format accents, and do any manipulation you desire on whatever order field.
So, here’s how they do it. Enjoy!

PHP Snippet: Alter Order Field Value After An Order is Placed @ WooCommerce Checkout
In this example, we’ll see how to re-format the phone number entered during checkout, by adding a prefix if it’s not there. Also, you’ll learn about the handy get_country_calling_code() WooCommerce function, which is good to know!
/**
* @snippet Update Order Meta After a Successful Order - WooCommerce
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 4.6
* @community https://businessbloomer.com/club/
*/
add_action( 'woocommerce_thankyou', 'bbloomer_alter_checkout_fields_after_order' );
function bbloomer_alter_checkout_fields_after_order( $order_id ) {
$order = wc_get_order( $order_id );
$phone = $order->get_billing_phone();
$calling_code = WC()->countries->get_country_calling_code( $order->get_billing_country() );
$calling_code = is_array( $calling_code ) ? $calling_code[0] : $calling_code;
if ( $phone && $calling_code && ! str_starts_with( $phone, $calling_code ) ) {
// str_starts_with() works on PHP 8+ only
$phone = $calling_code . $phone;
update_post_meta( $order_id, '_billing_phone', $phone );
}
}
Hi!
thanks for your code. Could be possible to use your code to remove special caractrs after order?
Yes, this can be coded of course!
Ho, I have not implemented this since WordPress does not support PHP 8 yet, but just from the code reading it looks like it does not work correctly. The phone number format without country prefix always starts with 0 (like 0912345678) and the international version of it leaves the zero out (like +421912345678). The php code above simply adds the local format to prefix and the number becomes incorrect: +4210912345678. Please correct me if I am wrong.
Honestly I don’t remember, it’s been a long time since I wrote this snippet. Have you tested it already?
Thanks Rodolfo, awesome stuff!
I like this code for writing a value to a native WC order field:
update_post_meta( $order_id, ‘_billing_phone’, $phone );
How can I write to an ACF Field? I have a boolean field ‘is_backorder’, I have my code that finds if the stock of any product is < 1, but I cannot for the life of it write anything to this custom field… Do you have any experience with ACF?
Help is much appreciated!
Daniel
Hi Daniel, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!