wc_clear_cart_after_payment

Clear cart after payment.

Description

wc_clear_cart_after_payment(); 

Usage

  1. if ( !function_exists( 'wc_clear_cart_after_payment' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-cart-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wc_clear_cart_after_payment(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-cart-functions.php  
  1. function wc_clear_cart_after_payment() { 
  2. global $wp; 
  3.  
  4. if ( ! empty( $wp->query_vars['order-received'] ) ) { 
  5.  
  6. $order_id = absint( $wp->query_vars['order-received'] ); 
  7. $order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : ''; 
  8.  
  9. if ( $order_id > 0 ) { 
  10. $order = wc_get_order( $order_id ); 
  11.  
  12. if ( $order && $order->get_order_key() === $order_key ) { 
  13. WC()->cart->empty_cart(); 
  14.  
  15. if ( WC()->session->order_awaiting_payment > 0 ) { 
  16. $order = wc_get_order( WC()->session->order_awaiting_payment ); 
  17.  
  18. if ( $order && $order->get_id() > 0 ) { 
  19. // If the order has not failed, or is not pending, the order must have gone through 
  20. if ( ! $order->has_status( array( 'failed', 'pending', 'cancelled' ) ) ) { 
  21. WC()->cart->empty_cart();