Providing a smart, seamless buying experience is a key part of increasing your conversion rate.

Avoiding those unnecessary steps in the checkout process helps to encourage the customer to complete the purchase.

WooCommerce offers an Add to cart redirect option that takes users directly to the cart page when they have added a product to the cart.

So instead of simply showing a ‚ÄúThis product has been added to the cart‚ÄĚ message, you can lead users directly to the cart page.

How do you set up an Add to Cart redirect on your WooCommerce store?

Here’s a step-by-step process to do it.

  1. Log into your WooCommerce dashboard
  2. Go to: WooCommerce> Settings> Products Tab> Display> Click Add to Cart Behavior
  3. Enable ‚ÄúRedirect to the cart page after successful addition‚ÄĚ by checking the box

If you want to redirect users to different, custom pages after they have added items to the cart, you can use a code snippet.

Now we will take a look at how we can set up Add to Cart Url to custom pages using a snippet.

Note: Do not add custom code directly to your parent theme’s functions.php file. This will be wiped entirely when you update the theme. Use the custom code on Child Theme’s functions.php file.

Redirect users to a custom page

To do this, you need to copy the following the snippet:

 /**
* Redirect users after add to cart.
*/
function my_custom_add_to_cart_redirect( $url ) {

$url = get_permalink( 1 ); // URL to redirect to (1 is the page ID here)

return $url;

}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
  1. Log into your WooCommerce 
  2. On the left side of the dashboard, go to go to Appearance>Theme Editor> functions.php
  3. Copy the snippet into the php file 
  4. Edit the snippet with the Page ID of the URL you want to redirect the user to.
  5. Save the php file

Redirect customers to the Checkout (WooCommerce)

If you sell only one or two products, you might want to redirect users directly to the checkout page once they have added items to the cart.

To do it, you just need to follow the steps we discussed in the snippet method above.

But you should use a different snippet as shown below.

<?php

/**

 * Redirect users after add to cart.

 */

function my_custom_add_to_cart_redirect( $url ) {

$url = WC()->cart->get_checkout_url();

// $url = wc_get_checkout_url(); // since WC 2.5.0

return $url;

}

add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
Need help to add this function to your WooCommerce store? Then Get in touch with us