mercredi 4 mars 2015

WooCommerce custom bulk action


I have succesfully created a custom bulk action, but the problem is, if I have several orders, it will only work for the first order. Lets say I have orders numbers #1, #2 and #3, the custom bulk action will only work for the order number #1.


Here is the sample of the code I use:



public function __construct () {
add_action( 'admin_footer-edit.php', array( $this, 'wb_my_action_order_status' ) );
add_action( 'load-edit.php', array( $this, 'my_action_custom_action' ) );
}

public function wb_my_action_order_status() {
global $post_type;
if($post_type == 'shop_order') {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('<option>').val('my_action').text('<?php _e('my_action', 'wb-my_action')?>').appendTo("select[name='action']");
jQuery('<option>').val('my_action').text('<?php _e('my_action', 'wb-my_action')?>').appendTo("select[name='action2']");
});
</script>
<?php
}

}


public function my_action_custom_action() {

global $typenow;
$post_type = $typenow;

if($post_type == 'shop_order') {
$wp_list_table = _get_list_table('WP_Posts_List_Table');
$action = $wp_list_table->current_action();

$allowed_actions = array("my_action");

if(!in_array($action, $allowed_actions)) return;

if(isset($_REQUEST['post'])) {
$orderids = array_map('intval', $_REQUEST['post']);
}

if(($action=='my_action') && ($order->status!='completed') ) {
// Here do the action
}

}
}


So what am I missing here?





Aucun commentaire:

Enregistrer un commentaire