wc_clear_cart_after_payment()
Clear cart after payment.
Description Description
Source Source
File: includes/wc-cart-functions.php
function wc_clear_cart_after_payment() { global $wp; if ( ! empty( $wp->query_vars['order-received'] ) ) { $order_id = absint( $wp->query_vars['order-received'] ); $order_key = isset( $_GET['key'] ) ? wc_clean( wp_unslash( $_GET['key'] ) ) : ''; // WPCS: input var ok, CSRF ok. if ( $order_id > 0 ) { $order = wc_get_order( $order_id ); if ( $order && hash_equals( $order->get_order_key(), $order_key ) ) { WC()->cart->empty_cart(); } } } if ( WC()->session->order_awaiting_payment > 0 ) { $order = wc_get_order( WC()->session->order_awaiting_payment ); if ( $order && $order->get_id() > 0 ) { // If the order has not failed, or is not pending, the order must have gone through. if ( ! $order->has_status( array( 'failed', 'pending', 'cancelled' ) ) ) { WC()->cart->empty_cart(); } } } }