I'm working on custom API for Merchant Safe Unipay (MSU) for woocommerce and need to change quantity after successful payment.
Here is process:
All works well but can't find hook where and how to mark all products from shopping card payed and change quantity.
How can I do that?
Thanks
Normally after payment process, the customer is redirected to "Thank you" page (or "Order received" where customer can review his payed order)… Normally the cart is emptied somewhere (I don't remember where exactly).
So if not emptied, you need to do it for example with (2 different hooks options):
add_action( 'woocommerce_checkout_order_processed', 'order_received_empty_cart_action', 10, 1 );
// or
// add_action( 'woocommerce_thankyou', 'order_received_empty_cart_action', 10, 1 );
function order_received_empty_cart_action( $order_id ){
WC()->cart->empty_cart();
}
The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
You will have to test that, to see if it's convenient…
With this code the payment is skipped. (Versión WC 3.5.7).
I include the code of class-wc-checkout.php
lines 983 - 989:
do_action( 'woocommerce_checkout_order_processed', $order_id, $posted_data, $order );
if ( WC()->cart->needs_payment() ) {
$this->process_order_payment( $order_id, $posted_data['payment_method'] );
} else {
$this->process_order_without_payment( $order_id );
}
If we clean the cart, it takes the else route:
$this->process_order_without_payment( $order_id );