Save shopping cart when a transaction is denied and redirected page

Asked

Viewed 31 times

1

My payment gateway has a problem when a transaction is denied, it redirects to another payment page that is all bugged up, so I created a second checkout page and am trying to redirect the denied payment to that page (redirecting to a duplicate of my checkout because I made some modifications to it, stating that the payment was denied, etc.), I created the following function:

function redirect_after_failed( $order_id, $order ) {
    global $wp;
    if ( is_wc_endpoint_url( 'order-pay' ) ) {
        $woocommerce->cart->empty_cart( false );
        wp_redirect( '/finalizar-2' );
        exit;
    }
}
add_action( 'wp', 'redirect_after_failed');

Works correctly when the user is logged in to an account, but in my store buyers do not create accounts, IE, works only for me in the admin account.

The problem I found is that the cart is only saved and not deleted when you have an account connected, when you are visitors the cart is not saved and is deleted.

I am days trying to find a solution to save the visitors' carts and when they are redirected the carts see keep, so they can go to the second checkout.

Thanks in advance.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.