几张便条!
如果您正在检查功能,则无需检查登录状态。访客(未登录)只有exists 能力,仅此而已。
而且wp_redirect() 应始终后跟exit; 在大多数情况下。在您的示例中,只有最后一个后跟exit;. 否则可能会创建循环。
我已经对您的代码进行了一些重构,我认为这应该可以:
add_action( \'template_redirect\', \'subscribers_redirection\' );
function subscribers_redirection() {
    $is_product_page = ( is_shop() || is_product_category() || is_product_tag() || is_product() );
    $is_logged_in    = is_user_logged_in();
    $is_subscriber   = current_user_can( \'subscriber\' );
    $is_customer     = current_user_can( \'customer\' );
    $redirect = false;
    if ( ! $is_logged_in && $is_product_page ) { // No need to check for user roles if the user isn\'t logged in.
        $redirect = home_url( \'/register\' );
    } else if ( $is_subscriber && ! $is_customer && $is_product_page ) {
        $redirect = home_url( \'/id-confirmation\' );
    } else if ( $is_customer && $is_product_page ) { // No need to check for a subscriber if the user already is a customer.
        $redirect = home_url( \'/shop\' );
    } else if ( $is_logged_in && is_page( \'register\' ) ) {
        $redirect = home_url( \'/my-account\' );
    } else if ( ! $is_subscriber && is_page( \'id-confirmation\' ) ) {
        $redirect = home_url( \'/register\' );
    }
    if ( $redirect ) {
        wp_redirect( $redirect );
        exit;
    }
}