2015-10-12 82 views
1

這是我在customer.updated webhook上獲得的JSON有效載荷。如何在woocommerce webhook中添加自定義字段?

{"customer":{"id":35,"created_at":"2015-10-09T06:51:25Z","email":"[email protected]","first_name":"Sagar","last_name":"Surwade","username":"connect91insagar","role":"customer","last_order_id":null,"last_order_date":null,"orders_count":0,"total_spent":"0.00","avatar_url":"http:\/\/1.gravatar.com\/avatar\/?s=96","billing_address":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping_address":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""}}} 

我需要密碼字段也是在這個JSON,因爲我將使用此同步兩個不同的系統。

謝謝。

回答

1

您可以嘗試連接過濾器「woocommerce_webhook_payload」。使用它提供的客戶ID來獲取用戶數據。使用它獲取密碼,將其添加到有效負載並將其傳回。這樣的事情:

add_action('woocommerce_webhook_payload', 'my_woocommerce_webhook_payload'); 

function my_woocommerce_webhook_payload($payload, $resource, $resource_id, $id) { 

    $user_info = get_userdata($payload["customer"]["id"]); 
    $payload["customer"]["found_password"] = $user_info->user_pass; 

    return $payload; 
} 

我已經成功地做了類似的工作,包括添加自定義字段的訂單數據。

+0

這不起作用,它返回'null' - ''customer「:{」found_password「:null}}' – Dan

相關問題