# Skip the Cart and Go Straight to Checkout

> Sends shoppers who open the cart page directly to checkout whenever their cart has products, shortening the path to purchase.

- Type: PHP
- Runs: Run everywhere
- Category: [Redirects](https://wpide.com/library/category/redirects/)
- Requires: WooCommerce
- Tags: woocommerce, cart, checkout
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-skip-cart-to-checkout/

## Code

```php
add_action( 'template_redirect', function () {
    if ( ! function_exists( 'is_cart' ) || ! is_cart() || ! function_exists( 'WC' ) || ! WC()->cart || WC()->cart->is_empty() ) {
        return;
    }

    wp_safe_redirect( wc_get_checkout_url() );
    exit;
} );
```

## Notes

An empty cart still shows the cart page with its "return to shop" message.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Skip the Cart and Go Straight to Checkout" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
