WooCommerce Redirect After Checkout

Recommendation

Learn why I switched to WPCodeBox for managing code snippets for myself and for my clients.

Instructions

Snippet Type: PHP

  1. Copy the snippet.
  2. Add the snippet using WPCodeBox.
  3. Follow any customization notes provided.
  4. Save the snippet.
  5. Enable the snippet.
  6. Test.

Snippet

This snippet is commonly used when website owners want to show customers a welcome page after checkout. Welcome pages are great ways to educate customers, upsell them, and more.

Customization Notes

Adjust the ‘$url = ‘https://domain.com/page’;’ with a URL from your own website.

				
					// WOOCOMMERCE REDIRECT AFTER CHECKOUT
add_action( 'woocommerce_welcome', 'wptu_redirectcustom');
  
function wptu_redirectcustom( $order_id ){
    $order = wc_get_order( $order_id );
    $url = 'https://domain.com/page';
    if ( ! $order->has_status( 'failed' ) ) {
        wp_safe_redirect( $url );
        exit;
    }
}