1// redirect empty checkouts and completed orders.
2add_action( 'template_redirect', 'myfunction' );
3function myfunction() {
4
5 if( is_wc_endpoint_url( 'order-received' ) && isset( $_GET['key'] ) ) {
6 wp_redirect('www.myurl.com'); // go to custom page if order has been received
7 exit;
8 }
9
10 if ( is_checkout() && 0 == WC()->cart->get_cart_contents_count() ) {
11 wp_safe_redirect( home_url() ); // if trying to access checkout with empty cart go back
12 exit;
13 }
14}