如何在woocommerce webhook中添加自定义字段?

时间:2015-10-12 07:53:58

标签: wordpress woocommerce

这是我在customer.updated webhook上获得的JSON有效负载。

{"customer":{"id":35,"created_at":"2015-10-09T06:51:25Z","email":"connect91insagar@gmail.com","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 个答案:

答案 0 :(得分: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;
}

我已经成功地为我添加自定义字段的订单数据做了类似的工作。