Skip to content
Blog Careers Google Partner 12+ Years · 5000+ Projects
Best Website design company in India September 6, 2020 2 min read

Redirect to custom url after woocommerce checkout

A redirect after WooCommerce checkout sends the customer to a page you choose, instead of the default order received page. This guide shows the code and where to put it.

How can you redirect clients to a perfectly looking, custom, item explicit thank you page?

Fortunately you can add some PHP code to your functions.php and characterize a redirect to a custom URL (instead of the default request got endpoint). This is an incredible route for you to include explicit up-sells, online media share and other data that could assist you with changing over extra sales.

Step 1:

 

Go to  Appearance > Theme Editor > functions.php

 

Step 2 : Copy and paste this code into functions.php file.

add_action( ‘template_redirect’, ‘woocommerce_redirect_after_checkout’ );

function woocommerce_redirect_after_checkout() {
global $wp;

if ( is_checkout() && ! empty( $wp->query_vars[‘order-received’] ) ) {

$redirect_url = ‘https://addonplus.in/my-account/orders/’;

wp_redirect($redirect_url );

exit;
}

}

Code for a redirect after WooCommerce checkout in functions.php

How the redirect after WooCommerce checkout works

The code runs on every page load and checks two things. First, is this the checkout? Second, does the address contain the order received endpoint, which appears only after a successful order? If both are true, WordPress sends the customer to the address in $redirect_url.

Replace the example address with your own thank-you page. However, remember that the default page shows the order summary. Therefore, your new page should confirm the order clearly, or customers may think the payment failed.

What to put on a custom thank-you page

  • A clear confirmation line and what happens next, such as the delivery time.
  • A related product or an offer for the next order.
  • Links to your WhatsApp or support number.
  • Conversion tracking for your advertising, because the default page will no longer load.

Before you add the code

Use a child theme or a code snippets plugin, because a theme update overwrites the parent theme’s functions.php. WordPress explains child themes in its developer handbook. Also take a backup first, and then place a test order with each payment method.

If you would like this set up for you, see our WooCommerce development services and our landing page design services.

See also: How do I create custom WooCommerce shop page? and Create location restriction in woocommerce.

Keep Reading

Related Articles

View All Articles