davidasor
davidasor

Reputation: 329

WooCommerce - how to disable redirect after place order

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?

Upvotes: 1

Views: 1659

Answers (2)

Lafif Astahdziq
Lafif Astahdziq

Reputation: 3986

You can prevent the redirect by omitting / nullify the redirect from the payment gateway process payment results

to remove from all payment gateways you can use the hook woocommerce_payment_successful_result, so for example

function remove_woocommerce_payment_successful_redirect( $result, $order_id ) {
    $result['redirect'] = false;
    $result['messages'] = '<div>Show something here</div>';
    return $result;
}
add_filter( 'woocommerce_payment_successful_result', 'remove_woocommerce_payment_successful_redirect', 10, 2 );

Upvotes: 0

Md. Delowar Hossen
Md. Delowar Hossen

Reputation: 561

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

        
    }
}

Upvotes: 0

Related Questions