All Articles

Enable order split from admin dashboard in dokan plugin

The multi-vendor plugin Dokan was created by the weDevs. It works in tandem with WooCommerce to give the WooCommerce website the flexibility to support multiple vendors.

When an order is placed with goods from various merchants on a multi-vendor website powered by the Dokan plugin. To divide the order, separate sub-orders are created for each vendor. The split of the order is perfect when a consumer creates it from the front-end. However, the order is not separated when it is created from the administrator dashboard. To make the order split from the dashboard available, use the following snippet of code.

<?php
/**
* Split orders when order containing products from multiple vendor is created from admin dashboard.
*/
function sagar_order_creation_fix( $post_id, $post, $update ) {
// Bail early if not admin.
if( ! is_admin() ) {
return;
}
// Split the order if the order is created.
if ( 'draft' === get_post_status( $post_id ) ) {
remove_action( 'save_post_shop_order', 'sagar_order_creation_fix', 10 );
$order_manager = new Dokan_Order_Manager();
$order_manager->maybe_split_orders( $post_id );
add_action( 'save_post_shop_order', 'sagar_order_creation_fix', 10, 3 );
}
}
add_action( 'save_post_shop_order', 'sagar_order_creation_fix', 10, 3 );