One of the most common WooCommerce customization requests developers receive is WooCommerce Add to Cart Redirects.
Whether it’s guiding buyers to checkout faster, promoting special offers, or customizing flows based on specific products, categories, user roles, or other conditions, smart redirects give your store better control over the customer journey.
In this tutorial, we’ll cover five real-world redirect scenarios that store owners frequently request, along with ready-to-use WooCommerce code snippets you can add directly to your theme’s functions.php file.
Solution: WooCommerce Add to Cart Redirects
1. Add to Cart Redirect for Specific Products
Sometimes, you may want to redirect customers for specific products, such as high-value items or limited-stock products, to speed up the purchase process. The following snippet allows you to define a list of product IDs. When one of these products is added to the cart, the customer is redirected directly to the checkout page.
Note: Before applying any of the redirect snippets, make sure to uncheck the option “Enable AJAX add to cart buttons on archives” under WooCommerce → Settings → Products → Add to cart behaviour.

// Redirect for specific product IDs
add_filter('woocommerce_add_to_cart_redirect', 'ts_redirect_specific_products');
function ts_redirect_specific_products($url) {
// Check if a product is being added to cart via standard (non-AJAX) request
if (!isset($_REQUEST['add-to-cart']) || !is_numeric($_REQUEST['add-to-cart'])) return $url;
$product_id = absint($_REQUEST['add-to-cart']); // Get the product ID from request
$redirect_products = array(195829, 195706, 42);// Add the IDs of products you want to redirect
// If the product ID matches the list, redirect to checkout
if (in_array($product_id, $redirect_products)) {
$url = wc_get_checkout_url(); // Redirects the user to checkout page
}
return $url;
}
When a customer clicks “Add to Cart” for one of these specified products, they are immediately redirected to the checkout page.

2. Add to Cart Redirect for Specific Categories
In some cases, you may want to redirect products that belong to a particular category, such as digital items or gift cards, directly to checkout. The code below checks whether the added product is part of a specific category and redirects accordingly.
// Redirect by product category
add_filter('woocommerce_add_to_cart_redirect', 'ts_redirect_by_category');
function ts_redirect_by_category($url) {
if (!isset($_REQUEST['add-to-cart']) || !is_numeric($_REQUEST['add-to-cart'])) return $url;
$product_id = absint($_REQUEST['add-to-cart']);
if (has_term('gift-cards', 'product_cat', $product_id)) {
$url = wc_get_checkout_url(); // Redirect category products to checkout
}
return $url;
}
If a customer clicks “Add to Cart” for a product from the clothing category, they are redirected directly to checkout.

3. Add to Cart Redirect for Certain Shipping Classes
Sometimes, products require special handling, like fragile items, and you may want to ensure customers move directly to checkout. By checking the shipping class of the product, you can apply a redirect only to items that need special attention.
// Redirect by shipping class
add_filter('woocommerce_add_to_cart_redirect', 'ts_redirect_by_shipping_class');
function ts_redirect_by_shipping_class($url) {
if (!isset($_REQUEST['add-to-cart']) || !is_numeric($_REQUEST['add-to-cart'])) return $url;
$product_id = absint($_REQUEST['add-to-cart']);
if (has_term('fragile-item', 'product_shipping_class', $product_id)) {
$url = wc_get_checkout_url(); // Redirect fragile items to checkout
}
return $url;
}
When a product belonging to the fragile shipping class is added to the cart, the customer is immediately redirected to checkout.

4. Add to Cart Redirect Based on User Role
Sometimes, you may want to provide a custom checkout experience for certain user roles, such as wholesale customers. The snippet below detects whether the logged-in user has a specific role and redirects them to a role-specific checkout page.
add_filter('woocommerce_add_to_cart_redirect', 'ts_redirect_by_user_role');
function ts_redirect_by_user_role($url) {
if (is_user_logged_in()) {
$user = wp_get_current_user();
if (in_array('wc1', (array) $user->roles)) {
$url = home_url('/wholesale-checkout/');
}
}
return $url;
}
When a wholesale user adds a product to the cart, they are redirected to /wholesale-checkout/.

5. Add to Cart Redirect Based on Customer Country
For international stores, it’s often useful to guide customers to country-specific checkout pages. The snippet below uses WooCommerce geolocation to detect a visitor’s country and redirect them to a dedicated checkout page if needed.
add_filter('woocommerce_add_to_cart_redirect', 'ts_redirect_ro_checkout');
function ts_redirect_ro_checkout($url) {
// Use WooCommerce geolocation
$geo = WC_Geolocation::geolocate_ip();
$country = $geo['country'];
if ($country === 'NL') {
$url = home_url('/nl-checkout/');
}
return $url;
}
When a user clicks the Add to Cart button, WooCommerce detects their geolocation based on IP. If the visitor is from the Netherlands (NL), they are automatically redirected to the /nl-checkout/ page. Customers from other countries continue to the default WooCommerce checkout page.

Instead of redirecting to a WooCommerce checkout page, you can redirect to any custom URL — a landing page, a promotional page, a country-specific info page, or even an external site.
Using the examples above, you can make the shopping experience smoother for your customers, guiding them exactly where you want them to go, whether that’s straight to checkout or a special promotional page.
To take it a step further, you can also see how to redirect users to another page after login in WooCommerce, so your store feels even more personalized from login to checkout.
