Woocommerce create order with hebrew text using th

2019-07-26 22:18发布

I am using woocommerce Version 2.3.10 (i cant upgrade to the new version) I am using API V2 I am creating an order using the API successfully The entire order text is in english once there is Hebrew in one of the fields (billing addres first name for example), I am getting an error when trying to create the order.

The error i am getting is: woocommerce_api_missing_callback_param Any ideas how to fix it? i tried to encode the text to unicode string but the string is not being decoded back to hebrew when the order is created. There is no problem to open an order with hebrew in the regular website (not using the api

UPDATE:
I installed latest version of woocommerce and the problem remains the same

2条回答
\"骚年 ilove
2楼-- · 2019-07-26 22:25

I have successfully created an order using API v2, used a Hebrew word for the first_name field and it worked. I am pasting the code here so that you can check yours against it.

  $p = $client->orders->create( 
        array (
            'payment_details' => array( 
                "method_id" => "bacs",
                "method_title" => "Direct Bank Transfer",
                "paid" => true
            ),

            'billing_address' => array( 
                "first_name" => "אֱלֹהִ֑ים",
                "last_name" => "Almighty",
                "address_1" => "969 Market",
                "address_2" => "",
                "city" => "San Francisco",
                "state" => "CA",
                "postcode" => "94103",
                "country" => "US",
                "email" => "john.doe@example.com",
                "phone" => "(555) 555-5555" 
            ),

            'shipping_address' => array( 
                "first_name" => "אֱלֹהִ֑ים",
                "last_name" => "Almighty",
                "address_1" => "969 Market",
                "address_2" => "",
                "city" => "San Francisco",
                "state" => "CA",
                "postcode" => "94103",
                "country" => "US"
            ),

            'line_items' => array(
                array( 
                    'product_id' => 579,
                    'quantity' => 2                     
                )               
            ),

            'shippling_lines' => array(
                array(
                    'method_id' => 'flat_rate',
                    'method_title' => 'Flat Rate',
                    'total' => 10                   
                )               
            ),


   ));

In the backend the order shows fine enter image description here

EDIT : Adding the request headers and body as requested by OP

Array
(
    [SERVER_SOFTWARE] => Apache/2.4.16 (FreeBSD) PHP/5.6.13 Phusion_Passenger/4.0.59
    [REQUEST_URI] => /wc-api/v2/orders?oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_s
ignature_method=HMAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [HOME] => /nonexistent
    [USER] => www
    [FCGI_ROLE] => RESPONDER
    [REDIRECT_STATUS] => 200
    [proxy-nokeepalive] => 1
    [HTTP_HOST] => wordpress
    [HTTP_ACCEPT] => application/json
    [CONTENT_TYPE] => application/json
    [HTTP_USER_AGENT] => WooCommerce API Client-PHP/2.0.1
    [CONTENT_LENGTH] => 734
    [PATH] => /sbin:/bin:/usr/sbin:/usr/bin
    [LD_LIBRARY_PATH] => /usr/local/lib
    [SERVER_SIGNATURE] =>
    [SERVER_NAME] => wordpress
    [SERVER_ADDR] => 192.168.1.11
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 192.168.1.11
    [DOCUMENT_ROOT] => /usr/home/anand/wordpress/
    [REQUEST_SCHEME] => http
    [CONTEXT_PREFIX] =>
    [CONTEXT_DOCUMENT_ROOT] => /usr/home/anand/wordpress/
    [SERVER_ADMIN] => you@example.com
    [SCRIPT_FILENAME] => /usr/home/anand/wordpress/index.php
    [REMOTE_PORT] => 13999
    [REDIRECT_QUERY_STRING] => oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_signature
_method=HMAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [REDIRECT_URL] => /wc-api/v2/orders
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => POST
    [QUERY_STRING] => oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_signature_method=H
MAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [SCRIPT_NAME] => /index.php
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 1442922853.0845
    [REQUEST_TIME] => 1442922853
)


{"order":{"payment_details":{"method_id":"bacs","method_title":"Direct Bank Transfer","paid":true},"billing_address":{"first_name":"\u05d0\u05b1\u05dc\u05b9\u05d4\u05b4\u0591\u05d9\u05dd","
last_name":"Almighty","address_1":"969 Market","address_2":"","city":"San Francisco","state":"CA","postcode":"94103","country":"US","email":"john.doe@example.com","phone":"(555) 555-5555"},
"shipping_address":{"first_name":"\u05d0\u05b1\u05dc\u05b9\u05d4\u05b4\u0591\u05d9\u05dd","last_name":"Almighty","address_1":"969 Market","address_2":"","city":"San Francisco","state":"CA",
"postcode":"94103","country":"US"},"line_items":[{"product_id":579,"quantity":2}],"shippling_lines":[{"method_id":"flat_rate","method_title":"Flat Rate","total":10}]}}

EDIT 2 : Adding C# specific piece of code

    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
    wc.Encoding = Encoding.UTF8;

    // Send the string as is
    string coupon = "{ \"coupon\": { \"code\": \"new-coupon\", \"type\": \"percent\", \"amount\": \"10\", \"individual_use\": true, \"product_ids\": [], \"exclude_product_ids\": [], \"usage_limit\": \"\", \"usage_limit_per_user\": \"\", \"limit_usage_to_x_items\": \"\", \"expiry_date\": \"\", \"enable_free_shipping\": false, \"product_category_ids\": [], \"exclude_product_category_ids\": [], \"exclude_sale_items\": true, \"minimum_amount\": \"100.00\", \"maximum_amount\": \"0.00\", \"customer_emails\": [], \"description\": \"אֱלֹהִ֑ים\" } }";
    var result = wc.UploadString(url, coupon);

    // Encode the string 
    string coupon = "{ \"coupon\": { \"code\": \"new-coupon1\", \"type\": \"percent\", \"amount\": \"10\", \"individual_use\": true, \"product_ids\": [], \"exclude_product_ids\": [], \"usage_limit\": \"\", \"usage_limit_per_user\": \"\", \"limit_usage_to_x_items\": \"\", \"expiry_date\": \"\", \"enable_free_shipping\": false, \"product_category_ids\": [], \"exclude_product_category_ids\": [], \"exclude_sale_items\": true, \"minimum_amount\": \"100.00\", \"maximum_amount\": \"0.00\", \"customer_emails\": [], \"description\": \"\\u05d0\\u05b1\\u05dc\\u05b9\\u05d4\\u05b4\\u0591\\u05d9\\u05dd\" } }";
    var result = wc.UploadString(url, coupon);
    return result;
查看更多
Explosion°爆炸
3楼-- · 2019-07-26 22:36

Solution:
The problem solved by adding encoding to the WebClient.
It worked in English without the encoding, but once I used Hebrew text i got errors from the woocommerce API.

WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
wc.Encoding = Encoding.UTF8;
查看更多
登录 后发表回答