mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-03 12:12:25 +08:00
13 lines
642 B
Text
13 lines
642 B
Text
add_action( 'woocommerce_thankyou', 'wc_alter_checkout_fields_after_order' );
|
|
|
|
function wc_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 );
|
|
}
|
|
}
|