Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

WebPro Care Latest Articles

Change WooCommerce Payment Status for Prepaid Orders

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';

}

}

}

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.

Related Posts

Leave a comment

Latest News & Updates

WebPro Care Latest Articles

Paw-some Supplies: Trending Pet Products on Amazon

Paw-some Supplies: Trending Pet Products on Amazon

Cozy Comfort: The Best Dog Beds When it comes to ensuring your furry friend gets a good night’s sleep, choosing the right dog bed is crucial. On Amazon, a diverse selection of dog beds caters to every need and preference. ...

Exploring the Trend: Modest Swimwear on Amazon

Exploring the Trend: Modest Swimwear on Amazon

Introduction to Modest Swimwear Modest swimwear is a term that encompasses a variety of swim attire designed to provide more coverage than traditional swimsuits. This style of swimwear has been gaining significant traction in recent years, appealing to a broad ...

6 Way to Improve Your Morning Coffee

6 Way to Improve Your Morning Coffee

Introduction: The Importance of a Good Morning Coffee For many individuals, a good morning coffee is more than just a beverage; it is an essential part of their daily routine. Starting the day with a well-prepared cup of coffee can ...

Explore Our Blog