Skip to content

Instantly share code, notes, and snippets.

@ucheng
Last active May 18, 2017 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ucheng/9229b4a5c92ba9eecab8a7a6a7d6f02a to your computer and use it in GitHub Desktop.
Save ucheng/9229b4a5c92ba9eecab8a7a6a7d6f02a to your computer and use it in GitHub Desktop.
<?php
//處理訂單狀態
add_filter( 'handle_bulk_actions-edit-shop_order', 'wootest_handle_bulk_actions_edit_product', 10, 3 );
function wootest_handle_bulk_actions_edit_product( $redirect_to, $action, $post_ids ) {
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( 'wc-awaiting-shipment' );
if( !in_array( $action, $allowed_actions ) ) return;
switch( $action ) {
case "wc-awaiting-shipment":
if ( count($post_ids) > 0 ) {
foreach( $post_ids as $order_id) {
$order = new WC_Order($order_id);
if($order->status != 'wc-awaiting-shipment' ) {
$order->update_status('wc-awaiting-shipment', 'order_note');
}
}
}
$redirect_to = add_query_arg( 'wootest_shop_order_update_results', count( $post_ids ), $redirect_to );
return $redirect_to;
break;
default: return;
}
}//end shop_order
}
//顯示notice
add_action( 'admin_notices', 'wootest_bulk_action_edit_shop_order_admin_notice' );
function wootest_bulk_action_edit_shop_order_admin_notice() {
if ( isset( $_REQUEST['wootest_shop_order_update_results'] ) ) {
$updated_shop_orders_count = intval( $_REQUEST['wootest_shop_order_update_results'] );
echo '<div id="message" class="' . ( $updated_shop_orders_count > 0 ? 'updated' : 'error' ) . '">';
if ( $updated_shop_orders_count > 0 ) {
echo '<p>' . __( 'Updated Orders for '. $updated_shop_orders_count .' '. _n( 'order', 'orders', $updated_shop_orders_count, 'wordpress' ).'!', 'wordpress' ) . '</p>';
} else {
echo '<p>' . __( 'No Orders were updated!', 'wordpress' ) . '</p>';
}
echo '</div>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment