The problem was solved with a small change
I put the code so that others can use it as well
// Deny purchase if already purchased
add_filter( 'woocommerce_is_purchasable', 'deny_purchase_if_already_purchased', 9999, 2 );
function deny_purchase_if_already_purchased( $is_purchasable, $product ) {
if ( is_user_logged_in() && wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) && get_post_status()!='private' ) {
$is_purchasable = false;
echo "already_purchased";
}
return $is_purchasable;
}