Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › Vendor Data on Order Metadata
- This topic has 5 replies, 2 voices, and was last updated 3 years, 5 months ago by
Sushobhan.
- AuthorPosts
- April 27, 2020 at 11:10 pm #123833
john.kaufmann
ParticipantHello,
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!
- April 28, 2020 at 2:28 pm #124127
Sushobhan
KeymasterHi,
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! - April 28, 2020 at 10:12 pm #124376
john.kaufmann
ParticipantThank 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..
- April 29, 2020 at 12:59 pm #124543
Sushobhan
KeymasterAs 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! - April 30, 2020 at 9:29 pm #125134
john.kaufmann
ParticipantThank 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? - May 1, 2020 at 12:19 am #125195
Sushobhan
KeymasterThe function is correct. No data implies, that vendor doesn’t fill his/her location details.
Thank You!
- AuthorPosts
- You must be logged in to reply to this topic.