WooCommerce Empty cart after payment with custom g

2019-06-02 04:26发布

I'm working on custom API for Merchant Safe Unipay (MSU) for woocommerce and need to change quantity after successful payment.

Here is process:

  1. Customer collect articles in shopping bag
  2. When click on "Pay All" it is redirected to MSU where need to fill Credit Card info
  3. After payment, MSU return him back to website where PHP send emails and print message about payment.

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

2条回答
ゆ 、 Hurt°
2楼-- · 2019-06-02 04:35

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 );
查看更多
爷的心禁止访问
3楼-- · 2019-06-02 04:41

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…

查看更多
登录 后发表回答