• Resolved didi3r

    (@didi3r)


    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

    https://www.ads-software.com/plugins/woocommerce/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Claudio Sanches

    (@claudiosanches)

    Hi @didi3r

    You can send custom data, but you’ll need custom code to do this.

    For example if you are working with products, you can use the woocommerce_api_product_response filter to add your custom fields.

    Here is an example of how to do this:

    function my_custom_products_api_fields( $product_data, $product ) {
        $product_data['your_custom_field_slug'] = get_post_meta( $product->id, 'your_custom_field_slug', true );
    
        return $product_data;
    }
    
    add_filter( 'woocommerce_api_product_response', 'my_custom_products_api_fields', 10, 2 );
    
    Thread Starter didi3r

    (@didi3r)

    Thanks for your help, your answer guided me to find the way to do it. I used the following code in case someone needs 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);

    Regards

    can you tell me which filed you updated?

    This’s how I added custom data to orders (not products):

    function my_custom_orders_api_fields( $order_data, $order ) {
        $order_data['your_custom_field_slug'] = get_post_meta( $order->id, 'your_custom_field_slug', true );
    
        return $order_data;
    }
    add_filter( 'woocommerce_api_order_response', 'my_custom_orders_api_fields', 10, 2 );

    can you tell me which files you updated?

    I put it into a custom plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Send custom data in woocommerce webhook’ is closed to new replies.