2015-10-12 60 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

相关问题