1
votes

I just create a custom status 'tree'('waiting in tree' - labeled) for my orders with the help of Custom Order Status for WooCommerce plugin. When the user successfully completed the payment the status will change from 'pending' to 'tree'.After some process, I will change the status to processing, at the time I need to send the processing mail to the user. How can I do this, I just find the above code to register the email.

function so_27112461_woocommerce_email_actions( $actions ){
        $actions[] = 'woocommerce_order_status_tree_to_processing';
        return $actions;
    }
    add_filter( 'woocommerce_email_actions', 'so_27112461_woocommerce_email_actions' );

But How can i trigger the processing mail.

1

1 Answers

1
votes

The plugin your are using is kind of outdated (not updated since WooCommerce 3 release).

You don't need any plugin to do what you want, just this few hooked functions below:

// Add custom status to order list
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
    register_post_status( 'wc-tree', array(
        'label'                     => _x( 'Waiting in tree', 'Order status', 'woocommerce' ),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Waiting in tree <span class="count">(%s)</span>', 'Waiting in tree <span class="count">(%s)</span>', 'woocommerce' )
    ) );
}

// Add custom status to order page drop down
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
    $order_statuses['wc-tree'] = _x( 'Waiting in tree', 'Order status', 'woocommerce' );
    return $order_statuses;
}
// Adding custom status 'tree' to admin order list bulk dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
    $actions['mark_tree'] = __( 'Mark Waiting in tree', 'woocommerce' );
    return $actions;
}

// Enable the action
add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
    $actions[] = 'woocommerce_order_status_wc-tree';
    return $actions;
}

// Send Customer Processing Order email notification when order status get changed from "tree" to "processing"
add_action('woocommerce_order_status_changed', 'custom_status_email_notifications', 20, 4 );
function custom_status_email_notifications( $order_id, $old_status, $new_status, $order ){
    if ( $old_status == 'tree' && $new_status == 'processing' ) {
        // Get all WC_Email instance objects
        $wc_emails = WC()->mailer()->get_emails();
        // Sending Customer Processing Order email notification
        $wc_emails['WC_Email_Customer_Processing_Order']->trigger( $order_id );
    }
}

Code goes in function.php file of your active child theme (or active theme). Tested and Works.