This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Try the fastest hosting platform with pay-as-you-go pricing & 24/7 expert support! MIGRATE NOW →

Change WooCommerce Payment Status for Prepaid Orders

Updated on April 20, 2021

3 Min Read
woocommerce payment status

WooCommerce order status management is an essential store operation that could take up a lot of your time. It is important that all the orders are regularly updated to reflect the most recent status.

Cash-on-Delivery is a very popular payment option that no WooCommerce store owner could overlook. However, there are scenarios where customers pre-pay for their purchases to speed up the fulfillment process. In such cases, there is a chance that even when the order has been fulfilled (dispatched and delivered to the customer), you might miss updating the order status.

Here’s a Simple WooCommerce Payment Status Solution

You can automate the process of updating the order status for orders that are pre-paid. The order gets updated to “Complete” automatically as soon as the WooCommerce payment status gets updated.

add_action('woocommerce_order_status_changed', 'woocommerce_payment_complete_order_status',10,3);
function woocommerce_payment_complete_order_status($order_id)
{
    if ( ! $order_id ) {
        return;
    }
    $order = wc_get_order( $order_id );
    if ($order->data['status'] == 'wc-processing') {
        $payment_method=$order->get_payment_method();
        if ($payment_method != "cod")
        {
            $order->update_status( 'wc-completed' );
        }
    }
}

How It Works

The code snippet uses the woocommerce_order_status_changed hook to call in the function when the order status gets changed. Once verifying that the order status is “Processing”, and the payment method IS NOT Cash-on-Delivery, the order status is changed to ‘Complete”

update_status() sets the order status that is passed to the method. Here is a brief list of the order status you can pass to this method:

<option value=”wc-pending”>Pending payment</option>

<option value=”wc-processing”>Processing</option>

<option value=”wc-on-hold”>On hold</option>

<option value=”wc-completed”>Completed</option>

<option value=”wc-cancelled”>Cancelled</option>

<option value=”wc-refunded”>Refunded</option>

<option value=”wc-failed”>Failed</option>

wc_get_order() is a wrapper function to get the order object that provides all data about a specific order.

Similarly, $order gets the order information as an object through wc_get_order() function. You can also use the following lines in the above code to get the order total in formatted format.

$order->get_id();

$order->get_formatted_order_total( );

At the checkout page, if you have selected “Cash on delivery” payment method as shown below:

After processing the order, you might see:

 WooCommerce Order Product Information

The following code snippet displays the products in an order. Note that this code snippet is to be placed at the location in the template file where you wish to display the information:

$filters = array(
'post_status' => 'any',
'post_type' => 'shop_order',
'orderby' => 'modified',
'order' => 'ASC'
);
$loop = new WP_Query($filters);
while ($loop->have_posts()) {
$loop->the_post();
$order = new WC_Order($loop->post->ID);
foreach ($order->get_items() as $key => $lineItem) {
echo '<br>' . 'Product Name : ' . $lineItem['name'];
echo 'Product ID : ' . $lineItem['product_id'];
if ($lineItem['variation_id']) {
echo 'Product Type : Variable Product';
} else {
echo 'Product Type : Simple Product';
}
}
}

If you are interested in changing the WooCommerce order change status based on order status, this short tutorial will provide you a simple solution. How to create custom WooCommerce order status.

Conclusion

Changing WooCommerce order status, particularly for the pre-paid orders is a simple matter of adding a simple code snippet to the WooCommerce template files. If you need help with implementing the idea, do leave a comment and I will get back to you.

Q. How do I change my payment status in WooCommerce?

Here’s how you can change your payment status in WooCommerce:

  • Go to the order page
  • Select the order
  • Click on “Edit” and choose the desired payment status from the dropdown menu.

Q. What is the default payment status in WooCommerce?

The default payment status in WooCommerce is “Pending,” which indicates that the payment for the order has not been completed or verified yet.

Q. How do I change my order status in WooCommerce?

You can enable HTTPS wrapper in PHP by enabling the OpenSSL extension in your PHP configuration file (php.ini) and ensuring that the necessary SSL/TLS libraries are installed on your server.

Q. How do I change orders from processing to complete in WooCommerce?

You can change orders from “Processing” to “Complete” in WooCommerce by navigating to the order page, selecting the order in question, clicking on “Edit,” and changing the order status to “Complete” from the dropdown menu.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at [email protected]

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now