Vendor Data on Order Metadata

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 5 reply threads
  • Author
    Posts
    • #123833
      john.kaufmann
      Participant

      Hello,

      I am using Woocommerce Order Export plugin, but need to have access to a Vendor’s ID, Vendor’s Address, and VAT / Tax ID. I’ve added a field in general settings for Vendors to enter in a VAT ID, but I can’t seem to find where Vendor information is attached to a Woocommerce order. Could you point me in the right direction or provide with a code snippet that might help? If you need any clarifying info I will provide. Thanks in advance!

    • #124127
      Sushobhan
      Keymaster

      Hi,
      You could use something like this snippet for your purpose. Please note the vendor id fetching logic is missing and needs to be implemented from your side-

      add_action( 'woocommerce_checkout_create_order_line_item', 'wcfm_add_vendor_order_line_item_meta', 10, 4 );
      function wcfm_add_vendor_order_line_item_meta( $item, $cart_item_key, $values, $order ) {
          $product = $values['data'];
          if ( $product ) {
              $product_id = $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id();
              $vendor = wcfm_get_vendor_id_by_post( $product_id );
              if ( $vendor ) {
                  $vat_id = 'abcdef'; //fetch the vat-id using the meta name you have used
                  if ( ! empty( $vat_id ) ) {
                      $item->update_meta_data( '_wcfm_vendor_vat_id', $vat_id );
                  }
              }
          }
      }
      
      add_filter( 'woocommerce_order_item_display_meta_key', function( $display_key, $meta = '' ) {
          if( $display_key == '_wcfm_vendor_vat_id' ) {
              $display_key = __( 'VAT ID' );
          }
          return $display_key;
      }, 50, 2 );

      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!

    • #124376
      john.kaufmann
      Participant

      Thank you that was helpful, definitely pulling me in the right direction!

      However I’m still having trouble figuring out where things are stored. I’ve store it like so:

      wcfm_update_user_meta( $vendor_id, 'wcfm_vendor_VAT_id', $wcfm_settings_form['wcfm_vendor_VAT_id'] );

      
      add_action( 'woocommerce_checkout_create_order_line_item', 'wcfm_add_vendor_order_line_item_meta', 10, 4 );
      function wcfm_add_vendor_order_line_item_meta( $item, $cart_item_key, $values, $order ) {
        $product = $values['data'];
        if ( $product ) {
          $product_id = $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id();
          $vendor_id = wcfm_get_vendor_id_by_post( $product_id );
          $vendor_data = wcfm_get_vendor_store_address_by_vendor( $vendor_id );
          if ( $vendor_id ) {
            debug_to_stdout($vendor_data);
            $_wcfm_vendor_VAT_id = wcfm_get_user_meta( $vendor_id, 'wcfm_vendor_VAT_id', true );
            if ( ! empty( $vat_id ) ) {
                $item->update_meta_data( '_wcfm_vendor_vat_id', $_wcfm_vendor_VAT_id );
                $item->update_meta_data( '_wcfm_vendor_address', $vendor_data );
            }
          }
        }
      }
      
      add_filter( 'woocommerce_order_item_display_meta_key', function( $display_key, $meta = '' ) {
        if( $display_key == '_wcfm_vendor_vat_id' ) {
          $display_key = __( 'VAT ID' );
        }
        if( $display_key == '_wcfm_vendor_address' ) {
          $display_key = __( 'VENDOR ADDRESS' );
        }
        return $display_key;
      }, 50, 2 );
      

      With that being said, this is what I’ve altered your code to. It’s showing up empty for address though..

    • #124543
      Sushobhan
      Keymaster

      As I can see there is a small mistake in the code. You have assigned a variable $_wcfm_vendor_VAT_id but checked with another variable ! empty( $vat_id ). Please fix that and then check again!
      Thank You!

    • #125134
      john.kaufmann
      Participant

      Thank you for that, that is a problem. However the wcfm_get_vendor_store_address_by_vendor( $vendor_id ); function is returning empty still. What is the appropriate way to get the vendor’s address from this hook?

    • #125195
      Sushobhan
      Keymaster

      The function is correct. No data implies, that vendor doesn’t fill his/her location details.
      Thank You!

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