在内部,WooCommerce使用WordPress\'wp_safe_redirect() 不允许重定向到外部主机。为了解决这个问题,我们必须将我们想要的主机添加到白名单中。可以使用allowed_redirect_hosts 具体如下:
/**
* 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;
}
将上述代码与原始代码一起使用(根据需要自定义主机),以允许WooCommerce用户在完成注册过程后重定向到外部域。