Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从商业订单中获得完整的州名?_Php_Wordpress_Woocommerce_Orders_Countries - Fatal编程技术网

Php 如何从商业订单中获得完整的州名?

Php 如何从商业订单中获得完整的州名?,php,wordpress,woocommerce,orders,countries,Php,Wordpress,Woocommerce,Orders,Countries,我是WordPress和WooCommerce插件之类的新手。我正在编写一个插件,我需要向一个SOAP API发送一些数据,情况是API只接受州全名,但我只从WooCommerce获得缩写形式 require_once("grutinet-web-service.php"); add_action('woocommerce_thankyou', 'send_order_grutinet'); function send_order_grutinet($order_id) {

我是WordPress和WooCommerce插件之类的新手。我正在编写一个插件,我需要向一个SOAP API发送一些数据,情况是API只接受州全名,但我只从WooCommerce获得缩写形式

require_once("grutinet-web-service.php");

add_action('woocommerce_thankyou', 'send_order_grutinet');
function send_order_grutinet($order_id)
{

// get order object and order details
$order = new WC_Order($order_id);

// set the address fields
$user_id = $order->get_user_id();
$address_fields = array(
    'country',
    'title',
    'first_name',
    'last_name',
    'company',
    'address_1',
    'address_2',
    'address_3',
    'address_4',
    'city',
    'state',
    'postcode'
);

$address = array();
if (is_array($address_fields)) {
    foreach ($address_fields as $field) {
        $address['billing_' . $field] = get_user_meta($user_id, 'billing_' . $field, true);
        $address['shipping_' . $field] = get_user_meta($user_id, 'shipping_' . $field, true);
    }
}


$numeroPedido   = $order_id;
$tipoPedido     = 'NORMAL';
$nombre         = $address['billing_first_name'] . $address['billing_last_name'];
$DniCif         = '41528741';
$direccion      = $address['shipping_address_1'] . ' - ' . $address['shipping_address_2'];
$codigoPostal   = $address['shipping_postcode'];
$poblacion      = $address['shipping_city'];
$provincia      = $order->get_shipping_state();
// $provincia      = $address['shipping_state'];
[...]
重要的一点是:

$provincia      = $order->get_shipping_state();
// $provincia      = $address['shipping_state'];

如何在此处获取完整的州名而不是缩写?

您可以使用以下内容显示国家和州代码中的州名:

$country_code = $order->get_shipping_country();
$state_code   = $order->get_shipping_state();

$countries = new WC_Countries(); // Get an instance of the WC_Countries Object

$country_states = $countries->get_states( $country_code ); // Get the states array from a country code
$state_name     = $country_states[$state_code]; // get the state name

// Display state name (for testing)
echo 'State name: ' . $state_name . '<br>';

可以使用以下选项显示国家/地区和州代码中的州名称:

$country_code = $order->get_shipping_country();
$state_code   = $order->get_shipping_state();

$countries = new WC_Countries(); // Get an instance of the WC_Countries Object

$country_states = $countries->get_states( $country_code ); // Get the states array from a country code
$state_name     = $country_states[$state_code]; // get the state name

// Display state name (for testing)
echo 'State name: ' . $state_name . '<br>';

谢谢,成功了,谢谢,成功了。