/**
  * Handles request to join the waitlist if user is not logged in
  *
  * Checks which waitlists need to be updated and processes the request, returning appropriate notifications upon completion
  *
  * @param $product
  *
  * @return admin notices for success/failure
  * @internal param val $mixed $product if multiple products need updating this will be an array, else the product object requiring updating
  * @access   public
  * @since    1.3
  */
 public function handle_waitlist_when_new_user($product)
 {
     if (is_array($product)) {
         $changed_products = $product;
         $product = $this->Product;
     }
     if (!isset($_REQUEST['wcwl_email']) || !is_email($_REQUEST['wcwl_email'])) {
         return WooCommerce_Waitlist_Plugin::add_notice(apply_filters('wcwl_join_waitlist_invalid_email_message_text', $this->join_waitlist_invalid_email_message_text), 'error');
     } elseif ($product->is_type('grouped') && empty($_REQUEST['wcwl_changed'])) {
         return WooCommerce_Waitlist_Plugin::add_notice(apply_filters('wcwl_toggle_waitlist_no_product_message_text', $this->toggle_waitlist_no_product_message_text), 'error');
     } else {
         if (email_exists($_REQUEST['wcwl_email'])) {
             $current_user = get_user_by('email', $_REQUEST['wcwl_email']);
         } else {
             $current_user = get_user_by('id', $product->Waitlist->create_new_customer_from_email($_REQUEST['wcwl_email']));
         }
         if ($product->is_type('grouped')) {
             $changed_products = isset($changed_products) ? $changed_products : array();
             foreach ($changed_products as $changed_product) {
                 $changed_product->Waitlist->register_user($current_user);
             }
             if (count($changed_products) > 1) {
                 return WooCommerce_Waitlist_Plugin::add_notice(apply_filters('wcwl_grouped_multiple_products_joined_message_text', $this->grouped_multiple_products_joined_message_text));
             }
             return WooCommerce_Waitlist_Plugin::add_notice(apply_filters('wcwl_grouped_single_product_joined_message_text', $this->grouped_single_product_joined_message_text));
         }
         if (!$product->Waitlist->register_user($current_user)) {
             return WooCommerce_Waitlist_Plugin::add_notice(apply_filters('wcwl_leave_waitlist_message_text', $this->leave_waitlist_message_text));
         }
         return WooCommerce_Waitlist_Plugin::add_notice(apply_filters('wcwl_join_waitlist_success_message_text', $this->join_waitlist_success_message_text));
     }
 }