'Prepare to Printing',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Prepare to Printing (%s)', 'Prepare to Printing (%s)')
));
register_post_status('wc-in-print', array(
'label' => 'In Printing',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('In Printing (%s)', 'In Printing (%s)')
));
}
/**
* Adds the wc-to-print order status to the list of WooCommerce order statuses
*
* @param array $order_statuses Existing order statuses
* @return array Modified order statuses
*/
public function add_to_print_order_status_to_list($order_statuses) {
$new_order_statuses = array();
// Add the custom status after the "Processing" status
foreach ($order_statuses as $key => $status) {
$new_order_statuses[$key] = $status;
if ($key === 'wc-processing') {
$new_order_statuses['wc-to-print'] = 'Prepare to Printing';
}
}
return $new_order_statuses;
}
/**
* Adds the wc-in-print order status to the list of WooCommerce order statuses
*
* @param array $order_statuses Existing order statuses
* @return array Modified order statuses
*/
public function add_in_print_order_status_to_list($order_statuses) {
$new_order_statuses = array();
// Add the custom status after the "Processing" status
foreach ($order_statuses as $key => $status) {
$new_order_statuses[$key] = $status;
if ($key === 'wc-to-print') {
$new_order_statuses['wc-in-print'] = 'In Printing';
}
}
return $new_order_statuses;
}
/**
* Adds the wc-to-print order status to the bulk actions dropdown
*
* @param array $bulk_actions Existing bulk actions
* @return array Modified bulk actions
*/
public function add_to_print_order_status_to_bulk_actions($bulk_actions) {
$bulk_actions['mark_to_print'] = 'Change status to Prepare to Printing';
return $bulk_actions;
}
/**
* Adds the wc-in-print order status to the bulk actions dropdown
*
* @param array $bulk_actions Existing bulk actions
* @return array Modified bulk actions
*/
public function add_in_print_order_status_to_bulk_actions($bulk_actions) {
$bulk_actions['mark_in_print'] = 'Change status to In Printing';
return $bulk_actions;
}
ends here
/**
* Handles the custom order status bulk action
*
* @param string $redirect_to The redirect URL
* @param string $action The bulk action being taken
* @param array $post_ids The IDs of the affected orders
* @return string The modified redirect URL
*/
public function handle_custom_order_status_bulk_action($redirect_to, $action, $post_ids) {
if ($action !== 'mark_custom-status') {
return $redirect_to;
}
foreach ($post_ids as $post_id) {
$order = wc_get_order($post_id);
$order->update_status('custom-status', 'Order status changed by bulk edit:', true);
}
$redirect_to = add_query_arg('bulk_custom_status_orders_count', count($post_ids), $redirect_to);
return $redirect_to;
}
/**
* Adds a timestamp meta data when an order status is changed
*
* @param int $order_id The ID of the order being changed
* @param string $old_status The old status of the order
* @param string $new_status The new status of the order
* @param WC_Order $order The order object
*/
public function add_status_change_timestamp($order_id, $old_status, $new_status, $order) {
$timestamp = current_time('mysql');
update_post_meta($order_id, '_status_changed_timestamp', $timestamp);
}
/**
* Adds a new column to the orders table for the status change timestamp
*
* @param array $columns Existing columns in the orders table
* @return array Modified columns
*/
public function add_order_status_changed_column($columns) {
$new_columns = array();
foreach ($columns as $column_name => $column_info) {
$new_columns[$column_name] = $column_info;
if ($column_name === 'order_status') {
$new_columns['order_status_changed'] = __('Status Changed', 'woocommerce');
}
}
return $new_columns;
}
/**
* Populates the custom column with the status change timestamp
*
* @param string $column The name of the column to populate
* @param int $post_id The ID of the order
*/
public function populate_order_status_changed_column($column, $post_id) {
if ($column == 'order_status_changed') {
$timestamp = get_post_meta($post_id, '_status_changed_timestamp', true);
if ($timestamp) {
echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($timestamp));
} else {
echo '—';
}
}
}
}
// Instantiate the plugin class
new Studiou_WC_Order_Print_Statuses();