Ritesh Ksheersagar
Ritesh Ksheersagar

Reputation: 562

How to add custom fields in a woocommerce webhook?

Here is the JSON payload i get on the customer.updated 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":""}}}

I need the password field also in this JSON since i will be using this to sync two different systems.

Thanks.

Upvotes: 1

Views: 3177

Answers (1)

Ricorocks
Ricorocks

Reputation: 21

You could try hooking into the filter "woocommerce_webhook_payload". Use the Customer ID it gives you to get the user data. Use this to get the password, add it to the payload and pass it back. Something like this:

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;
}

I've had success doing similar with including data for orders where I've added custom fields.

Upvotes: 2

Related Questions