Created
September 14, 2020 17:25
-
-
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.
This file contains hidden or 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
<?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