k1eran
0
Q:

template_redirect woocommerce display notice example

// redirect empty checkouts and completed orders.
add_action( 'template_redirect', 'myfunction' );
function myfunction() {

    if( is_wc_endpoint_url( 'order-received' ) && isset( $_GET['key'] ) ) {
        wp_redirect('www.myurl.com'); // go to custom page if order has been received
        exit;
    }

    if ( is_checkout() && 0 == WC()->cart->get_cart_contents_count() ) {
       wp_safe_redirect( home_url() ); // if trying to access checkout with empty cart go back
       exit;
    }  
}
0

New to Communities?

Join the community