add_filter('woocommerce_is_purchasable', 'disable_add_to_cart_for_specific_product', 10, 2); function disable_add_to_cart_for_specific_product($purchasable, $product) { if (is_user_logged_in()) { $specific_product_id_1 = 3819; $specific_product_id_2 = 3815; $specific_product_id_3 = 3050; // Retrieve the post ID for the checked JoomSport season $args = array( 'post_type' => 'joomsport_season', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'joomsport_season_live', 'value' => 'on', ), ), ); $posts = get_posts($args); $checked_season_post_id = ''; foreach ($posts as $post) { $checked_season_post_id = $post->ID; } // Get the current user and their purchased season $current_user = wp_get_current_user(); $billing_season = get_user_meta($current_user->ID, 'billing_season', true); if ($billing_season == $checked_season_post_id) { // Allow purchasing of Product ID 3819 regardless of other purchases if ($product->get_id() == $specific_product_id_1) { return true; } // Check if Product ID 3819 has been purchased $product_3819_purchased = wc_customer_bought_product($current_user->user_email, $current_user->ID, $specific_product_id_1); // Disable purchasing of Product ID 3815 and 3050 if not purchased before if (!$product_3819_purchased && ($product->get_id() == $specific_product_id_2 || $product->get_id() == $specific_product_id_3)) { return false; } } } return $purchasable; }