Allow only 1 quantity of particular product in cart WooCommerce

Try with this

add_filter( 'woocommerce_add_to_cart_validation', 'allowed_products_variation_in_the_cart', 10, 5 );

function allowed_products_variation_in_the_cart( $passed, $product_id, $quantity, $variation_id, $variations) {

    $product_a = 14576;
    $product_b = 14091;

    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
        $cart_product_id = $cart_item['product_id'];
        if ($cart_item['variation_id']) {
            $cart_product_id = $cart_item['variation_id'];
        }

        if ( ($cart_product_id == $product_a && $variation_id == $product_b) || ($cart_product_id == $product_b && $variation_id == $product_a) ) {

            wc_add_notice(__('You can\'t add this product.', 'domain'), 'error');
            $passed = false; // don't add the new product to the cart
            // We stop the loop
            break;
        }
    }

    return $passed;
}