Ecommerce Shopify WordPress Discussion

Trying to edit the order status of an incomplete (pending payment) order

I have a situation where I need to change the order status where users don't complete payment. Basically I can't have orders in pending payment (except for one category of product which I've accounted for in my code) Actually my code works, however, it's the hook that I need help with. I've tried using woocommerce_checkout_order_processed but this fires too early. It interrupts the checkout process and cancels the order (as woocommerce creates an order and puts it in 'pending payment' immediately and before payment is processed). I've also tried woocommerce_thankyou but this doesn't fire at all when user closes payment window and navigates away from the checkout (but order is created and 'pending'). Here's the code I have with the hook being used add_action( 'woocommerce_checkout_order_processed', 'tjn_set_cancelled_for_unpaid_orders' ); function tjn_set_cancelled_for_unpaid_orders( $order_id ) { $order = wc_get_order( $order_id ); $isVirtual = false; $isHidden = false; foreach ($order->get_items() as $order_item){ $item = wc_get_product($order_item->get_product_id()); if ($item->is_virtual()) { $isVirtual = true; } if ($item->get_catalog_visibility() == 'hidden') { $isHidden = true; } } if ($isVirtual && !$isHidden) { if ($order->has_status('pending')) { $order->update_status( 'cancelled' ); } } } Thanks in advance for any assistance!
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.