• Hello!

    I am trying to send some custom data to my order webhook.
    Basically I am using WC Vendors PRO Plugin, so I need to send the vendor address to the webhook.

    I have followed this other post but it’s not working for me.
    https://www.ads-software.com/support/topic/send-custom-data-in-woocommerce-webhook

    The $vendor_id is null and nothing is being populated on the json.

    Here’s my code:

    function my_custom_orders_api_fields($payload) {
    
    $vendor_shop = urldecode( get_query_var( ‘vendor_shop’ ) );
    $vendor_id = get_the_author_meta(‘ID’);
    
    $shop_name = get_user_meta( $vendor_id, ‘pv_shop_name’, true );
    
    $payload[‘loja’][‘nome’] = $shop_name;
    
    return $payload;
    }
    
    add_filter( ‘woocommerce_api_order_response’, ‘my_custom_orders_api_fields’, 10, 2 );

    Any ideas?
    thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello Andre,

    If you can query the product ID, then query the post_author for the products post ID. That’s the vendor. From there, the world is yours!

    function my_custom_orders_api_fields($payload) {
    
    $post = $order->id;
    
    $items = $order->get_items();
    foreach ( $items as $item ) {
    $product_id = $item['product_id'];
    }
    
    $vendor_id = get_post_field( 'post_author', $product_id );
    
    $shop_name = get_user_meta( $vendor_id, ‘pv_shop_name’, true );
    
    $payload[‘loja’][‘nome’] = $shop_name;
    
    return $payload;
    }
    
    add_filter( ‘woocommerce_api_order_response’, ‘my_custom_orders_api_fields’,
    Thread Starter andrefc

    (@andrefc)

    Awesome thank you bnoleite!
    I will give it a try!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom data to Webhook’ is closed to new replies.