WooCommerce - how to disable redirect after place order

Viewed 30

I trying to make all in one page for my checkout. My issue is in checkout page when clicking on place order button, a redirect to payment page will happen.

is there a way to disable the redirect after placing the order successfully, to avoid moving to the next page?

1 Answers

you can change redirect page by using the below code..

add_action( 'template_redirect', 'woo_order_received_redirection_to_my_account' );
function woo_order_received_redirection_to_my_account() {
    // Only on "Order received" page
    if( is_wc_endpoint_url('order-received') ) {
        global $wp;

        // Get the Order Object
        $order = wc_get_order( absint($wp->query_vars['order-received']) ); 

        // My account redirection url
        $my_redirect_url = get_permalink( get_option('woocommerce_myaccount_page_id') );

        // if you want to redirect cart page...
        // $my_redirect_url = home_url( 'checkout' );

        wp_redirect( $my_redirect_url );
        exit(); // Always exit

        
    }
}
Related