Include Vendor Name and Address in Order

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Viewing 6 reply threads
  • Author
    Posts
    • #128260
      supportw1
      Participant

      Hello we are trying to integrate woocommerce to Zapier to use a delivey app, we need to include the vendor name and address along the order so Zapier can pull the information, how can we do this?

      Thanks a lot!

      Attachments:
      You must be logged in to view attached files.
    • #128415
      Sushobhan
      Keymaster

      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!

    • #128575
      supportw1
      Participant
      This reply has been marked as private.
    • #128578
      supportw1
      Participant
      This reply has been marked as private.
    • #129080
      Sushobhan
      Keymaster

      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!

    • #130157
      supportw1
      Participant
      This reply has been marked as private.
    • #130303
      Sushobhan
      Keymaster

      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!

Viewing 6 reply threads
  • You must be logged in to reply to this topic.