Search
Close this search box.

How to redirect cart and skip directly to checkout in WooCommerce

To redirect the “Cart” page to the checkout page in WooCommerce using the functions.php file, you can use the template_redirect action hook. This hook allows you to perform actions before the template is loaded on the front-end of your site.

Here is an example of how you can use this hook to redirect the “Cart” page to the checkout page:

// Redirect cart and skip directly to checkout in WooCommerce
// More snippets at wpunplugged.com 

function redirect_cart_to_checkout() {
    if ( is_cart() ) {
        wp_safe_redirect( wc_get_checkout_url() );
        exit;
    }
}
add_action( 'template_redirect', 'redirect_cart_to_checkout' );

In this example, we are using the is_cart() function to check if the current page is the “Cart” page, and the wp_safe_redirect() function to redirect the user to the checkout page if it is.

It’s important to note that this code will redirect the user to the checkout page every time they visit the “Cart” page. If you only want to redirect the user on certain conditions, you will need to add additional checks before the redirect.

Share this post

You might also like...

Comment

Your email address will not be published. Required fields are marked *