Answers for "template_redirect woocommerce display notice example"

PHP
0

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;
    }  
}
Posted by: Guest on August-27-2020

Code answers related to "template_redirect woocommerce display notice example"

Browse Popular Code Answers by Language