Commerce Cart Redirection

Redirects users to checkout, cart, or a custom URL after adding a product to their cart in Drupal Commerce stores.

commerce_cart_redirection
1,769 sites
24
drupal.org

Install

Drupal 11, 10 v3.3.0
composer require 'drupal/commerce_cart_redirection:^3.3'
Drupal 9 v3.2.1
composer require 'drupal/commerce_cart_redirection:^3.2'

Overview

Commerce Cart Redirection enhances the Drupal Commerce shopping experience by automatically redirecting customers after they add a product to their cart. This streamlines the checkout process by eliminating extra clicks and guiding customers directly to where you want them to go.

The module provides flexible configuration options to control which product variation types trigger the redirection. You can choose to redirect to the checkout page, the cart page, or any custom URL of your choice. Additionally, there's an option to clear the cart before adding a new item, which is useful for single-product purchase flows or membership/subscription sites.

The "Add to Cart" button text can also be customized for products that will trigger the redirection, allowing you to display more contextually appropriate labels like "Buy Now" or "Subscribe" instead of the default "Add to Cart" text.

Features

  • Redirect users to checkout page immediately after adding a product to cart for streamlined purchasing
  • Redirect users to cart page to review their order before proceeding to checkout
  • Configure a custom redirect URL (local or external) for specialized workflows
  • Select specific product variation bundles to apply the redirection behavior
  • Negate bundle selection to redirect for all product types except the selected ones
  • Clear the cart of existing items before adding a new item, useful for single-product purchase flows
  • Customize the 'Add to Cart' button text for products that trigger redirection (e.g., 'Buy Now', 'Subscribe')

Use Cases

Quick Buy / Express Checkout

For stores selling single products or wanting to minimize the purchase funnel, configure the module to redirect directly to checkout after adding any product. This removes the cart review step and speeds up conversions. Enable 'Clear cart before add' if you only want one product per order.

Subscription or Membership Sales

When selling subscriptions or memberships where customers should only purchase one at a time, select the subscription product variation bundle(s), enable redirection to checkout, and enable 'Clear cart before add'. Change the button text to 'Subscribe Now' for clarity.

Digital Download Store

For digital product stores where customers typically buy one item at a time, configure specific digital product variation bundles to redirect directly to checkout. Physical products can go to the cart normally by using the negate option.

Event Ticket Sales

For event ticketing where you want users to complete the purchase immediately after selecting tickets, redirect event ticket product variations to checkout. The cart clearing option ensures each purchase is a separate transaction.

Service Booking

When selling services that require immediate booking/payment (consultations, appointments), redirect service product types directly to checkout with a custom button label like 'Book Now' to clarify the action.

Mixed Product Types with Different Flows

For stores with both quick-purchase items and items requiring review, select only the quick-purchase product variation types for redirection. Use the negate option if most products should redirect except for a few complex ones.

Tips

  • When selecting 'Other' for the redirection route, you can use internal Drupal paths (like /contact) or external URLs (like https://payment.example.com). Internal paths should start with a forward slash.
  • The 'Clear cart before add' option preserves the quantity specified in the add-to-cart request. For example, if a customer adds 3 items, only those 3 items will be in the cart after clearing.
  • Combine this module with Commerce Product Limits if you need to restrict the quantity of specific products customers can purchase, rather than just clearing the cart.
  • The module uses a two-phase redirect approach (setting a request attribute then redirecting on response) to ensure compatibility with other modules that may modify the cart during the add-to-cart process.
  • Consider user experience when changing button text - 'Buy Now' implies immediate purchase while 'Add to Cart' implies browsing continues. Match the text to your redirect destination.

Technical Details

Admin Pages 1
Commerce Cart Redirection /admin/commerce/config/commerce_cart_redirection

Configure which product variation types trigger redirection after adding to cart, choose the destination URL, and set advanced options like clearing the cart before adding new items.

Permissions 1
Configure Commerce Cart Redirection

Allows users to access and modify the Commerce Cart Redirection settings page at /admin/commerce/config/commerce_cart_redirection

Hooks 2
hook_help

Provides help text for the module's help page explaining the module's purpose.

hook_form_alter

Modifies the add-to-cart form to change the 'Add to Cart' button text when the product variation matches the configured bundles and custom button text is specified.

Troubleshooting 5
Redirection is not working after installation

By default, the module does not redirect any requests. Navigate to /admin/commerce/config/commerce_cart_redirection and either select specific product variation bundles OR check the 'Negate the Bundles condition' checkbox to redirect all products.

No products are being redirected even though settings are configured

If you have both selected all product bundles AND enabled the negate option, no products will be redirected due to the logical inversion. Either deselect some bundles or uncheck the negate option.

Custom URL redirect is not working

Ensure the custom URL is valid and properly formatted. The module performs basic URL validation using UrlHelper::isValid() but does not verify that the destination exists. Check that the URL is accessible and correctly entered (including protocol for external URLs).

Add to Cart button text is not changing

The button text replacement only works for products whose variation bundle is configured for redirection. Verify that the product's variation type is selected (or not selected when using negate) in the module configuration.

Checkout redirect fails with 'Page not found'

The checkout redirect requires Commerce Checkout module to be installed. If using an alternative checkout system (like BigCommerce), the module will fall back to the front page. Use the 'Other' option with a custom URL for your checkout path.

Security Notes 2
  • The custom URL field accepts any URL without server-side destination validation. Ensure administrators with the 'configure commerce_cart_redirection' permission are trusted, as they could potentially redirect customers to malicious external sites.
  • The module properly uses Drupal's URL generation and validation utilities (Url::fromRoute, UrlHelper::isValid) to construct safe redirect URLs for the built-in checkout and cart options.