Get Dokan Seller details from WooCommerce order item

How to get the Dokan Vendor's Warehouse Address from a WooCommerce Order? The Long Version: I'm working on a WordPress/WooCommerce plugin for Automated shipment booking for which I need the Pickup Address, the catch is that, it's a Multi-vendor WooCommerce setup using Dokan plugin, so I just wanted to understand the way to get the Vendor's warehouse address against the WooCommerce Order. I've tried the WooCommerce Documentation to see if they have any seller related helpers, I've checked various built-in classes provided by WooCommerce to see if there is any way to fetch the seller details. I've tried searching for Dokan Documentation, but they don't have any concrete documentation to help me here.

Comment (1)

Jese Leos

August 10, 2024

Verified user

With Dokan plugin, There is not really a vendor Warehouse Address. You can get the vendor details from a defined WC_Order object $order via order items: // Loop through order "line items" foreach ( $order->get_items() as $item ) { $author_id = get_post_field( 'post_author', $item->get_product_id() ); $vendor = dokan()->vendor->get($author_id); $shop_name = $vendor->get_shop_name(); // <== Shop name $first_name = $vendor->get_first_name(); // <== First name $last_name = $vendor->get_first_name(); // <== Last name $address = $vendor->get_address(); // <== Address $location = $vendor->get_location(); // <== Location $phone = $vendor->get_phone(); // <== Phone $email = $vendor->get_email(); // <== Email } The only case where the vendor can define a Warehouse Address is when enabling Cash on delivery shipping option, where a Warehouse Address can be optionally defined in the "description" field. See it here in the documentation. This Warehouse Address should be stored in the database in Dokan proprietary tables, as in WooCommerce, there is NO description field in Cash on delivery shipping option. This Warehouse Address could be available (without any guaranty) in order "shipping" items, from a defined WC_Order object $order: // Loop through order "line items" foreach ( $order->get_items('shipping') as $item ) { // raw output shipping data print_r($item->get_data()); // raw output shipping meta data print_r($item->get_meta_data()); } I hope it will help. Related: Display Dokan custom order meta data in WooCommerce order list How to get WooCommerce order details Get Order items and WC_Order_Item_Product in WooCommerce 3 Get orders shipping items details in WooCommerce 3

You’ll be in good company