didi3r
didi3r

Reputation: 227

Send custom data in woocommerce webhook

I have a store working with woocommerce plugin for wordpress and everytime a customer purchase something I record that sale in an internal software I'm using to track my shipments and inventory. To do this I'm using the webkooks feature of woocommerce and everything works fine, but now, I want to send some custom data in the webhook request. I have tried using "custom fields" or "product attributes" in my product but neither those fields are sent by the webhook request. So my question is, is there a way I can send aditional data in the webhook?

Thanks in advance.

Upvotes: 2

Views: 4220

Answers (1)

didi3r
didi3r

Reputation: 227

I got it working, I used the following code to achieved it:

function add_order_item_meta($item_id, $values) {
    $key = 'an_identifier';
    $value = get_post_meta( $values['product_id'], 'custom_field_name', true );
    woocommerce_add_order_item_meta($item_id, $key, $value);
}
add_action('woocommerce_add_order_item_meta', 'add_order_item_meta', 10, 2);

Upvotes: 4

Related Questions