Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › Include Vendor Name and Address in Order
- This topic has 6 replies, 2 voices, and was last updated 4 years, 6 months ago by Sushobhan.
Viewing 6 reply threads
- AuthorPosts
- May 8, 2020 at 10:32 am #128260
- May 8, 2020 at 6:24 pm #128415SushobhanKeymaster
Hi,
Thanks for getting in touch with us!
You can add store information under order line-items using the following snippet-add_filter( 'woocommerce_rest_prepare_shop_order_object', function( $response, $order, $request ) { global $WCFM; $order_data = $response->get_data(); foreach ( $order_data['line_items'] as $key => $item ) { $author_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $item['product_id'] ); if ( $author_id ) { $order_data['line_items'][$key]['store'] = array( 'id' => $author_id, 'name' => $WCFM->wcfm_vendor_support->wcfm_get_vendor_store_name_by_vendor( $author_id ), 'shop_name' => $WCFM->wcfm_vendor_support->wcfm_get_vendor_store_name_by_vendor( $author_id ), 'url' => wcfmmp_get_store_url( $author_id ), 'address' => $WCFM->wcfm_vendor_support->wcfm_get_vendor_address_by_vendor( $author_id ) ); } } $response->set_data( $order_data ); return $response; }, 30, 3 );
Add this code to your child theme’s functions.php
In case you do not have child theme then add code using this plugin – https://wordpress.org/plugins/code-snippets/
Let me know how this goes.
Thanks! - May 9, 2020 at 12:50 am #128575supportw1ParticipantThis reply has been marked as private.
- May 9, 2020 at 12:53 am #128578supportw1ParticipantThis reply has been marked as private.
- May 10, 2020 at 11:39 am #129080SushobhanKeymaster
Hi,
Kindly replace your previous snippet with this new one-add_filter( 'woocommerce_rest_prepare_shop_order_object', function( $response, $order, $request ) { global $WCFM; $order_data = $response->get_data(); foreach ( $order_data['line_items'] as $key => $item ) { $vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $item['product_id'] ); if ( $vendor_id && wcfm_is_vendor( $vendor_id ) ) { $store_user = wcfmmp_get_store( $vendor_id ); $email = $WCFM->wcfm_vendor_support->wcfm_vendor_has_capability( $vendor_id, 'vendor_email' ) ? $store_user->get_email() : ''; $phone = $WCFM->wcfm_vendor_support->wcfm_vendor_has_capability( $vendor_id, 'vendor_phone' ) ? $store_user->get_phone() : ''; $store_info = $store_user->get_shop_info(); $address_coordinate = array(); if ( ! empty( $store_info['store_lat'] ) && ! empty( $store_info['store_lng'] ) ) { $address_coordinate['store_lat'] = $store_info['store_lat']; $address_coordinate['store_lng'] = $store_info['store_lng']; } $order_data['line_items'][$key]['store'] = array( 'id' => $vendor_id, 'shop_name' => $store_user->get_shop_name(), 'url' => $store_user->get_shop_url(), 'address' => $store_user->get_address(), 'address_coordinate' => $address_coordinate, 'email' => $email, 'phone' => $phone, ); } else { $order_data['line_items'][$key]['store'] = array(); } } $response->set_data( $order_data ); return $response; }, 30, 3 );
Let me know how it goes.
Thank You! - May 12, 2020 at 10:26 pm #130157supportw1ParticipantThis reply has been marked as private.
- May 13, 2020 at 10:09 am #130303SushobhanKeymaster
Hi,
That is coming from WooCommerce. The response has customer billing and shipping addresses, so you can use Google Geocoding API to get the Lat, Lng.
Thank You!
- AuthorPosts
Viewing 6 reply threads
- You must be logged in to reply to this topic.