Last active
June 16, 2020 15:09
-
-
Save morevnaproject/6a49bbbcb5d5baa329081a708818140d to your computer and use it in GitHub Desktop.
WooCommerce - Automatic transliteration of Shipping/Billing from Cyrillic to Latin symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cyr2lat($text){ | |
$cyr = [ | |
'а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п', | |
'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я', | |
'А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П', | |
'Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я' | |
]; | |
$lat = [ | |
'a','b','v','g','d','e','yo','zh','z','i','i','k','l','m','n','o','p', | |
'r','s','t','u','f','h','ts','ch','sh','shсh','\'','y','\'','e','yu','ya', | |
'A','B','V','G','D','E','Yo','Zh','Z','I','Y','K','L','M','N','O','P', | |
'R','S','T','U','F','H','Ts','Ch','Sh','Shсh','\'','Y','\'','E','Yu','Ya' | |
]; | |
return str_replace($cyr, $lat, $text); | |
} | |
add_action( 'woocommerce_new_order', 'action_fix_shipping_address' ); | |
function action_fix_shipping_address( $order_id ){ | |
$order = wc_get_order( $order_id ); | |
$order->set_billing_first_name( cyr2lat($order->get_billing_first_name()) ); | |
$order->set_billing_last_name( cyr2lat($order->get_billing_last_name()) ); | |
$order->set_billing_company( cyr2lat($order->get_billing_company()) ); | |
$order->set_billing_address_1( cyr2lat($order->get_billing_address_1()) ); | |
$order->set_billing_address_2( cyr2lat($order->get_billing_address_2()) ); | |
$order->set_billing_city( cyr2lat($order->get_billing_city()) ); | |
$order->set_billing_state( cyr2lat($order->get_billing_state()) ); | |
$order->set_shipping_first_name( cyr2lat($order->get_shipping_first_name()) ); | |
$order->set_shipping_last_name( cyr2lat($order->get_shipping_last_name()) ); | |
$order->set_shipping_company( cyr2lat($order->get_shipping_company()) ); | |
$order->set_shipping_address_1( cyr2lat($order->get_shipping_address_1()) ); | |
$order->set_shipping_address_2( cyr2lat($order->get_shipping_address_2()) ); | |
$order->set_shipping_city( cyr2lat($order->get_shipping_city()) ); | |
$order->set_shipping_state( cyr2lat($order->get_shipping_state()) ); | |
$order->save(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment