Skip to content

Commit

Permalink
feat: add vendor bulk order status change (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonh3 authored and sabbir1991 committed Jul 16, 2018
1 parent 3eae92f commit f3137b0
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 113 deletions.
46 changes: 46 additions & 0 deletions assets/js/dokan.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,52 @@ jQuery(function($) {
}
});

/**
* Change bulk order status in vendor dashboard
*/
var change_bulk_order_status = {
init: function() {
selected_orders = [];

$( '#cb-select-all' ).on( 'change', function( e ) {
var self = $(this);

var order_id = $( '.cb-select-order' );

if ( self.is( ':checked' ) ) {
order_id.each( function ( key, value ) {
var order = $( value );

order.prop( 'checked', 'checked' );

selected_orders.push( order.data( 'order_id' ) );
} );
} else {
order_id.each( function ( key, value ) {
$( value ).prop( 'checked', '' );
selected_orders.pop();
} );
}
} );

$( '.cb-select-order' ).on( 'change', function( e ) {
var self = $(this);

if ( self.is( ':checked' ) ) {
selected_orders.push( self.data( 'order_id' ) );
} else {
var index = selected_orders.indexOf( self.data( 'order_id' ) );

if ( index !== -1) {
selected_orders.splice( index, 1 );
}
}
} );
}
};

change_bulk_order_status.init();

})(jQuery);


Expand Down
46 changes: 46 additions & 0 deletions assets/src/js/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,5 +513,51 @@ jQuery(function($) {
}
});

/**
* Change bulk order status in vendor dashboard
*/
var change_bulk_order_status = {
init: function() {
selected_orders = [];

$( '#cb-select-all' ).on( 'change', function( e ) {
var self = $(this);

var order_id = $( '.cb-select-order' );

if ( self.is( ':checked' ) ) {
order_id.each( function ( key, value ) {
var order = $( value );

order.prop( 'checked', 'checked' );

selected_orders.push( order.data( 'order_id' ) );
} );
} else {
order_id.each( function ( key, value ) {
$( value ).prop( 'checked', '' );
selected_orders.pop();
} );
}
} );

$( '.cb-select-order' ).on( 'change', function( e ) {
var self = $(this);

if ( self.is( ':checked' ) ) {
selected_orders.push( self.data( 'order_id' ) );
} else {
var index = selected_orders.indexOf( self.data( 'order_id' ) );

if ( index !== -1) {
selected_orders.splice( index, 1 );
}
}
} );
}
};

change_bulk_order_status.init();

})(jQuery);

41 changes: 41 additions & 0 deletions includes/wc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,3 +1021,44 @@ function dokan_get_more_products_from_seller( $seller_id = 0, $posts_per_page =

wp_reset_postdata();
}

/**
* Change bulk order status in vendor dashboard
*
* @since 2.8.3
*
* @return string
*/
function dokan_bulk_order_status_change() {
if ( ! current_user_can( 'dokan_manage_order' ) ) {
return;
}

if ( ! isset( $_POST['security'] ) || ! wp_verify_nonce( $_POST['security'], 'bulk_order_status_change' ) ) {
return;
}

if ( ! isset( $_POST['status'] ) || ! isset( $_POST['bulk_orders'] ) ) {
return;
}

$status = $_POST['status'];
$orders = $_POST['bulk_orders'];

// -1 means bluk action option value
if ( $status === '-1' ) {
return;
}

foreach ( $orders as $order ) {
$the_order = new WC_Order( $order );

if ( $the_order->get_status() == $status ) {
continue;
}

$the_order->update_status( $status );
}
}

add_action( 'template_redirect', 'dokan_bulk_order_status_change' );
Loading

0 comments on commit f3137b0

Please sign in to comment.