60

How to Redirect WooCommerce Users After Checkout

Powered by WPCodeBox

Easily redirect WooCommerce users to a custom URL after checkout by adjusting the ‘$url = ‘‘;’ in the provided code snippet.


/**
 * Author: WP Turned UP
 * Author URI: https://wpturnedup.com
 */
 
// 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;
    }
}

Other Snippets

WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.