Skip to content

Instantly share code, notes, and snippets.

@trey8611
Created September 14, 2020 17:25
Show Gist options
  • Save trey8611/df11cf50b4deecc2c3e587a0dfef4799 to your computer and use it in GitHub Desktop.
Save trey8611/df11cf50b4deecc2c3e587a0dfef4799 to your computer and use it in GitHub Desktop.
WP All Export - WooCommerce Orders - Convert country code or state code to full names.
<?php
// Use these on the Order ID element in an export.
function my_get_country( $order_id ) {
$order = wc_get_order( $order_id );
if ( empty( $order ) ) return;
$country = $order->get_shipping_country();
$countries = WC()->countries->countries;
if ( array_key_exists( $country, $countries ) ) {
return $countries[ $country ];
}
}
function my_get_state( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) return;
$state = $order->get_shipping_state();
if ( empty( $state ) ) return;
$states = WC()->countries->get_states( $order->get_shipping_country() );
if ( isset( $states[ $state ] ) ) {
return $states[ $state ];
} else {
return $state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment