Automating Order Status Change After Full Payment in WooCommerce

Managing order statuses effectively in WooCommerce is essential for streamlining the purchasing process and ensuring customers are well-informed. By default, WooCommerce allows for order status updates via plugins, but when dealing with split payments using the Deposits & Partial Payments plugin by Acowebs, the automation process requires additional configuration. This guide will walk you through automating the transition from In Progress to Completed after the final payment has been received.


Understanding the Order Status Workflow

WooCommerce orders typically go through multiple status changes. The relevant ones in this scenario are:

  • In Progress: The order is currently being processed, with partial payment made.
  • Completed: The order is fulfilled, and the customer has fully paid.

With the Deposits & Partial Payments plugin, the order remains in In Progress status until the second payment is completed. Our goal is to automatically change the status to Completed upon receiving the final payment.


Solution Approaches

1. Using a Custom Code Snippet

A custom code snippet can be added to your WooCommerce installation to automate the status change. You can achieve this by hooking into the payment completion event.

Steps to Implement Custom Code:

  1. Access Your Functions File
    • Navigate to your WordPress admin panel.
    • Go to Appearance > Theme Editor.
    • Open the functions.php file of your active theme.
  2. Add the Following Code:
add_action('woocommerce_order_status_processing', 'update_order_status_after_full_payment', 10, 1);

function update_order_status_after_full_payment($order_id) {
    if (!$order_id) return;
    
    $order = wc_get_order($order_id);
    
    // Check if the order is using the Deposits & Partial Payments plugin
    if (function_exists('awcdp_get_order_remaining_balance')) {
        $remaining_balance = awcdp_get_order_remaining_balance($order_id);
        
        if ($remaining_balance == 0) {
            // Change the order status to completed
            $order->update_status('completed', __('Final payment received, order completed.', 'woocommerce'));
        }
    }
}

2. Using a WooCommerce Automation Plugin

If you prefer a plugin-based solution, you can use workflow automation plugins like:

  • AutomateWoo
  • WooCommerce Order Status Manager
  • WP All Import (for bulk changes)
See also  How to export orders from woocommerce ?

Example Setup with AutomateWoo:

  1. Install and activate AutomateWoo.
  2. Go to AutomateWoo > Workflows > Add New.
  3. Create a trigger: Order Updated.
  4. Set conditions: Check if the remaining balance is zero.
  5. Set an action: Change order status to Completed.

Testing & Debugging

After implementing the solution, test it with a sample order:

  1. Place an order with the deposit option.
  2. Complete the first payment and check the order status.
  3. Make the final payment and verify if the status changes to Completed.
  4. If the status does not change, check WooCommerce logs under WooCommerce > Status > Logs for any errors.

Conclusion

By implementing the above methods, you can ensure that orders automatically transition to Completed only after the customer has fully paid. Whether using a custom PHP solution or a plugin, this setup enhances workflow efficiency and customer satisfaction.

Leave a Reply

Your email address will not be published. Required fields are marked *