简体   繁体   中英

WooCommerce - How to Reprocess a Placed Order for Development Testing

I'm building a small plugin (WordPress/WooCommerce) that sends order data from a placed order to an external system.

The sequence of the process is simple. When this action is triggered:

add_action('woocommerce_thankyou', array($this, 'xc_woocommerce_thankyou'));

I use wp_remote_post to send the order data to my external system.

The problem is, I'm having to run these tests a lot because I'm pulling data from various metadata sources (from other plugins) in WooCommerce and so I need to test repeatedly. This takes a lot of time as I have to set the cart up again and again before placing the order.

My question: is there a way to "reverse" the "Place Order" so that the cart gets reinstated so that I can run it repeatedly for tests?

woocommerce_thankyou 

hook runs every time the thankyou page loads. So process your order and once you land on the thank you page just keep refreshing the page and your method will run each time with the same order number and cart information.

Because of this I would recommend using the

woocommerce_order_status_processing

hook after you have finished your testing or similar as it only runs once. This method also allow you to if there is an issue re-send the order by changing the order status to pending and then back to processing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM