// Check if user is logged in if ( is_user_logged_in() && is_product() ) { global $product; $current_user = wp_get_current_user(); $product_id = $product->get_id(); // Check if the current user has bought the current product if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id ) ) { // Message to display if the user already owns the product $message = '

✅ You already own this product.

'; // For downloadable products, you can provide a direct link to downloads if ($product->is_downloadable()) { $message .= '

View your downloads

'; } else { // For other products, provide a link to the my account page $message .= '

Manage in My Account

'; } // Output the custom message and links, preventing the add to cart button from showing echo $message; return true; // Stop standard button from displaying } } return false; // Continue to show standard button }