Last active
May 18, 2017 06:22
-
-
Save ucheng/9229b4a5c92ba9eecab8a7a6a7d6f02a to your computer and use it in GitHub Desktop.
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 | |
//處理訂單狀態 | |
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