Last active
December 1, 2017 16:39
-
-
Save max-kk/c31777f505757d93d76aa4dcfff5edb1 to your computer and use it in GitHub Desktop.
Add Bulk actions to Woocommerce products list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHP 5.3 and WP 4.7 is required | |
*/ | |
//apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); | |
// Add our actions to list | |
add_filter( "bulk_actions-edit-shop_order", function($actions) { | |
$statuses = wc_get_order_statuses(); | |
foreach ($statuses as $key => $name) { | |
$actions[ 'set-' . $key] = "Set status \"" . $name . "\""; | |
} | |
return $actions; | |
}, 9 ); | |
// Process Action | |
add_action( "admin_init", function() { | |
// Make sure that we on "Woocomerce orders list" page | |
if ( !isset($_GET['post_type']) || $_GET['post_type'] != 'shop_order' ) { | |
return; | |
} | |
if ( isset($_GET['action']) && 'set-' === substr( $_GET['action'], 0, 4 ) ) { | |
// Check Nonce | |
if ( !check_admin_referer("bulk-posts") ) { | |
return; | |
} | |
// Remove 'set-' from action | |
$new_status = substr( $_GET['action'], 4 ); | |
$posts = $_GET['post']; | |
foreach ($posts as $postID) { | |
if ( !is_numeric($postID) ) { | |
continue; | |
} | |
$order = new WC_Order( (int)$postID ); | |
$order->update_status( $new_status, 'Bulk actions' ); | |
} | |
} | |
}, 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment