All Articles

Enable order split from admin dashboard in dokan plugin

Dokan Photo by Shahadat Shemul on Unsplash

Dokan is a multi-vendor plugin developed by the weDevs. It works along side with the WooCommerce to allow the multi-vendor capability to the WooCommerce website.

In a multi-vendor website based on Dokan plugin, when an order is created containing products from multiple vendors. The order is split by creating sub-order for each vendor. When a customer creates order from front-end, the order is split perfectly. But when the order is created from the administrator dashboard, the order is not split. Use the following code snipped to enable the order split from the dashboard.

* 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() ) {
// 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 );