Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created December 11, 2024 11:14
Show Gist options
  • Select an option

  • Save webtoffee-git/37de7219cfdfa46a8d7b9269cad51d56 to your computer and use it in GitHub Desktop.

Select an option

Save webtoffee-git/37de7219cfdfa46a8d7b9269cad51d56 to your computer and use it in GitHub Desktop.
Code to alter order billing and shipping state code to state names - By WebToffee (Order import export plugin for woocommere)
<?php //Do not copy this line of code
add_filter('hf_alter_csv_order_data', 'hf_alter_csv_order_data_callback', 10, 2);
function hf_alter_csv_order_data_callback($order_export_data, $filter_args ) {
$order_id = $order_export_data['order_id'];
if( $order_id ){
$order = wc_get_order($order_id);
// Get the shipping state code from the order
$shipping_state = $order->get_shipping_state();
// Get the country code from the order
$shipping_country = $order->get_shipping_country();
if( ''!== $shipping_state ){
// Get the state name using the country and state code
$state_name = WC()->countries->get_states( $shipping_country )[$shipping_state];
$order_export_data['shipping_state'] = $state_name;
}
// Get the billing state code from the order
$billing_state = $order->get_billing_state();
// Get the country code from the order
$billing_country = $order->get_billing_country();
if( ''!== $billing_state ){
// Get the state name using the country and state code
$state_name = WC()->countries->get_states( $billing_country )[$billing_state];
$order_export_data['billing_state'] = $state_name;
}
}
return $order_export_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment