In WooCommerce, you can use WordPress functions to set the order status to "completed" after a successful payment. You can achieve this using hooks and functions provided by WooCommerce. Here's an example of how you can set the order status to "completed" after a successful payment:

function custom_update_order_status($order_id) {

    // Get the order object

    $order = wc_get_order($order_id);

    // Check if the order status is 'processing' or 'on-hold'

    if (in_array($order->get_status(), array('processing', 'on-hold'))) {

        // Mark the order as 'completed'

        $order->update_status('completed');

    }

}

add_action('woocommerce_payment_complete', 'custom_update_order_status');

Here's what this code does:

  1. It defines a custom function custom_update_order_status that takes the $order_id as a parameter.

  2. Inside the function, it uses wc_get_order($order_id) to get the WooCommerce order object associated with the $order_id.

  3. It checks if the current order status is 'processing' or 'on-hold' using in_array.

  4. If the order status matches 'processing' or 'on-hold', it updates the order status to 'completed' using $order->update_status('completed').

  5. Finally, it hooks this function to the woocommerce_payment_complete action, which is triggered after a successful payment is made.

With this code, when a payment is successfully completed for an order that was in 'processing' or 'on-hold' status, it will be automatically updated to 'completed' status. Make sure to add this code to your theme's functions.php file or a custom plugin.