Last active
January 10, 2018 17:54
-
-
Save danschumann/344508be340ac6ae7c22cfb192306e9e to your computer and use it in GitHub Desktop.
Batch update several orders in WOOCommerce (acf field
This file contains hidden or 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 | |
add_filter( "bulk_actions-edit-shop_order", function($actions) { | |
?> | |
<script> | |
jQuery(document).ready(function($){ | |
$('#bulk-action-selector-top') | |
// This field will let us enter a batch number for this action | |
.after('<input id="batch-number-input" name="batch-number" />') | |
// Show/hide input if update batch is selected | |
.change(function(e) { | |
$('#batch-number-input')[e.target.value == 'update-batch' ? 'show' : 'hide']() | |
}) | |
// Ensure it's hidden on page load ( or shown if they clicked back ) | |
.trigger('change') | |
; | |
}) | |
</script> | |
<?php | |
$actions[ 'update-batch'] = "Update Batch Number"; | |
return $actions; | |
}, 9 ); | |
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']) && 'update-batch' == $_GET['action'] ) { | |
// Check Nonce | |
if ( !check_admin_referer("bulk-posts") ) { | |
return; | |
} | |
$batchNumber = $_GET['batch-number']; | |
$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' ); | |
update_field('batch-number', $batchNumber, (int)$postID); | |
} | |
wp_redirect(wp_get_referer()); | |
} | |
}, 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment