Skip to content

Instantly share code, notes, and snippets.

@ucheng
Created April 22, 2021 14:28
Show Gist options
  • Save ucheng/7897f1bc390f56f82915d5c3e97600ee to your computer and use it in GitHub Desktop.
Save ucheng/7897f1bc390f56f82915d5c3e97600ee to your computer and use it in GitHub Desktop.
build custom shipping address
<?php
// $raw_address = Array (
// [first_name] => YU CHENG
// [last_name] => WANG
// [company] =>
// [address_1] => 新北路
// [address_2] =>
// [city] => 板橋區
// [state] => NEW TAIPEI CITY
// [postcode] => 100
// [country] => TW
// )
$country = $order->get_shipping_country(); // country code, ex: TW
$city = $order->get_shipping_city();
$states = WC()->countries->get_states(); // state codes
$state = $order->get_shipping_state(); // shipping state code
$full_state = ( $country && $state && isset($states[$country][$state])) ? $states[$country][$state] : $state;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment