The Dokan plugin manages vendors as users with the seller
(Vendor) user role.
When the customer places the order, an "admin" order is created which includes the products of all vendors (including shipping costs, etc.) and as many other sub-orders as there are vendors from which the customer is buying.
For each sub-order, the post meta _dokan_vendor_id
is also stored, the value of which is the user id of the vendor.
Also, if the frontend of the marketplace also shows products that do not belong to any vendor, you can add an additional check to verify that that user actually has the "seller" (Vendor) user role.
Because the plugin stores the post meta _dokan_vendor_id
with the product author id, it does not check the seller
user role.
Then, you can change the order id like this:
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number', 99, 2 );
function change_woocommerce_order_number( $order_id ) {
// Gets the vendor id from the order.
$vendor_id = get_post_meta( $order_id, '_dokan_vendor_id', true );
// For vendor orders only
if ( $vendor_id && user_can( $vendor_id, 'seller' ) ) {
$vendor = get_user_by( 'id', $vendor_id );
$vendor_name = $vendor->display_name;
return "VK/$order_id-$vendor_name";
}
return $order_id;
}
The code has been tested and works. Add it to your active theme's functions.php.
NOTE
Obviously the order number modified through the woocommerce_order_number
hook is only in display. The order ID on the database is always and only numeric. So if you want to get the order number with this structure (for example in the export of orders) you will need to create a custom function.