wc_clear_cart_after_payment()
Clear cart after payment.
Description Description
Source Source
File: includes/wc-cart-functions.php
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | 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(); } } } } |