3 Reworded for clarity.
source | link

Internally, WooCommerce passes the host to be redirected to the WordPress core functionuses WordPress' wp_safe_redirect(), which does not allow non-local redirects by defaultto external hosts. HoweverIn order to get around this, we can use the allowed_redirect_hosts filter tomust add our externaldesired host to the whitelist which will allow the redirect to work. The whitelist can be modified using the allowed_redirect_hosts which has been demonstrated below:

/**
 * Adds example.com to the list of allowed hosts when redirecting using wp_safe_redirect()
 *
 * @param array       $hosts An array of allowed hosts.
 * @param bool|string $host  The parsed host; empty if not isset.
 */
add_filter( 'allowed_redirect_hosts', 'wpse_allowed_redirect_hosts', 10, 2 );
function wpse_allowed_redirect_hosts( $hosts, $host ) {
    $hosts[] = 'example.com';

    return $hosts;
}

Use the code above along with your original code (customizing the host as needed) to allow WooCommerce users to be redirected to an external domain after completing the registration process.

WooCommerce passes the host to be redirected to the WordPress core function wp_safe_redirect(), which does not allow non-local redirects by default. However, we can use the allowed_redirect_hosts filter to add our external host to the whitelist which will allow the redirect to work.

/**
 * Adds example.com to the list of allowed hosts when redirecting using wp_safe_redirect()
 *
 * @param array       $hosts An array of allowed hosts.
 * @param bool|string $host  The parsed host; empty if not isset.
 */
add_filter( 'allowed_redirect_hosts', 'wpse_allowed_redirect_hosts', 10, 2 );
function wpse_allowed_redirect_hosts( $hosts, $host ) {
    $hosts[] = 'example.com';

    return $hosts;
}

Internally, WooCommerce uses WordPress' wp_safe_redirect() which does not allow redirects to external hosts. In order to get around this, we must add our desired host to the whitelist. The whitelist can be modified using the allowed_redirect_hosts which has been demonstrated below:

/**
 * Adds example.com to the list of allowed hosts when redirecting using wp_safe_redirect()
 *
 * @param array       $hosts An array of allowed hosts.
 * @param bool|string $host  The parsed host; empty if not isset.
 */
add_filter( 'allowed_redirect_hosts', 'wpse_allowed_redirect_hosts', 10, 2 );
function wpse_allowed_redirect_hosts( $hosts, $host ) {
    $hosts[] = 'example.com';

    return $hosts;
}

Use the code above along with your original code (customizing the host as needed) to allow WooCommerce users to be redirected to an external domain after completing the registration process.

2 Use same variable names as docs. Improved wording.
source | link

WooCommerce passes the redirect locationhost to be redirected to the WordPress core function wp_safe_redirect(), which does not allow non-local redirects by default. However, we can use the allowed_redirect_hosts filter to add our external domainhost to the whitelist which will allow the external redirect to work.

/**
 * Adds example.com to the list of allowed hosts when redirecting using wp_safe_redirect()
 *
 * @param array       $hosts An array of allowed hosts.
 * @param bool|string $host  The parsed host; empty if not isset.
 */
add_filter( 'allowed_redirect_hosts', 'wpse_allowed_redirect_hosts', 10, 2 );
function wpse_allowed_redirect_hosts( $allowed_hosts$hosts, $parsed_host$host ) {
    $allowed_hosts[]$hosts[] = 'example.com';

    return $allowed_hosts;$hosts;
}

WooCommerce passes the redirect location to the WordPress core function wp_safe_redirect(), which does not allow non-local redirects by default. However, we can use the allowed_redirect_hosts filter to add our external domain to the whitelist which will allow the external redirect to work.

/**
 * Adds example.com to the list of allowed hosts when redirecting using wp_safe_redirect()
 *
 * @param array       $hosts An array of allowed hosts.
 * @param bool|string $host  The parsed host; empty if not isset.
 */
add_filter( 'allowed_redirect_hosts', 'wpse_allowed_redirect_hosts', 10, 2 );
function wpse_allowed_redirect_hosts( $allowed_hosts, $parsed_host ) {
    $allowed_hosts[] = 'example.com';

    return $allowed_hosts;
}

WooCommerce passes the host to be redirected to the WordPress core function wp_safe_redirect(), which does not allow non-local redirects by default. However, we can use the allowed_redirect_hosts filter to add our external host to the whitelist which will allow the redirect to work.

/**
 * Adds example.com to the list of allowed hosts when redirecting using wp_safe_redirect()
 *
 * @param array       $hosts An array of allowed hosts.
 * @param bool|string $host  The parsed host; empty if not isset.
 */
add_filter( 'allowed_redirect_hosts', 'wpse_allowed_redirect_hosts', 10, 2 );
function wpse_allowed_redirect_hosts( $hosts, $host ) {
    $hosts[] = 'example.com';

    return $hosts;
}
1
source | link

WooCommerce passes the redirect location to the WordPress core function wp_safe_redirect(), which does not allow non-local redirects by default. However, we can use the allowed_redirect_hosts filter to add our external domain to the whitelist which will allow the external redirect to work.

/**
 * Adds example.com to the list of allowed hosts when redirecting using wp_safe_redirect()
 *
 * @param array       $hosts An array of allowed hosts.
 * @param bool|string $host  The parsed host; empty if not isset.
 */
add_filter( 'allowed_redirect_hosts', 'wpse_allowed_redirect_hosts', 10, 2 );
function wpse_allowed_redirect_hosts( $allowed_hosts, $parsed_host ) {
    $allowed_hosts[] = 'example.com';

    return $allowed_hosts;
}