How to redirect to another page after completing the purchase in Woocommerce

Codelapa | top woocommerce plugins 1200x675 1 | Desenvolvimento de E-commerce

Some agencies require correct URLs to measure conversions, installing pixels, events, and scripts. This is not a difficult task when using the Google Tag Manager platform.

Some developers and designers find WooCommerce’s post-purchase page a bit rigid, so we decided to create a code snippet that redirects users to a desired page:

add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom' );
function bbloomer_redirectcustom( $order_id ) {
  $order = wc_get_order( $order_id );
  $url = 'https://exemplo.com.br';
  if ( ! $order->has_status( 'failed' ) ) {
    wp_safe_redirect( $url );
    exit;
  }
}

Copy and paste the code above into your functions.php file.

Remember to replace the example URL with the one you want!

Leave a Reply

Continuando a usar, você concorda que codelapa.com.br pode armazenar cookies em seu dispositivo e divulgar informações de acordo com nossa Política de Cookies.