I have created my custom order status Pending Approval as Default Order Status, Means if a customer order something from store, it will place it under Pending Approval instead of Processing, Here's my code to create custom status:
function register_my_order_status() {
register_post_status( 'wc-pending-approval', array(
'label' => 'Pending Approval',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'exclude_from_orders_screen' => false,
'add_order_meta_boxes' => true,
'exclude_from_order_count' => false,
'exclude_from_order_views' => false,
'exclude_from_order_webhooks' => false,
'exclude_from_order_reports' => false,
'exclude_from_order_sales_reports' => false,
'label_count' => _n_noop( 'Pending Approval <span class="count">(%s)</span>', 'Pending Approval <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_my_order_status' );
// Add to list of WC Order statuses
function add_my_order_statuses( $order_statuses ) {
$new_order_statuses = array();
// add new order status after processing
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-pending' === $key ) {
$new_order_statuses['wc-pending-approval'] = 'Pending Approval';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_my_order_statuses' );
To make it default status, I've edited this file:
wp-content/plugins/woocommerce/includes/gateways/cod/class-wc-gateway-cod.php
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
// Mark as processing (payment won't be taken until delivery)
//$order->update_status( 'processing', __( 'Payment to be made upon delivery.', 'woocommerce' ) );
$order->update_status( 'pending-approval', __( 'Payment to be made upon delivery.', 'woocommerce' ) );
...
As you can see I've commented default status(Processing) to "Pending Approval"..
Now the Problem is it's not sending New Order emails to Admin & Customers because it's my custom status and it's unknown status for woocommerce, I haven't changed anything other than this for Custom Status, Kindly help me in this regard..
Thanks :)