Exemple #1
0
 /**
  * Get registered users for product waitlist
  *
  * @since 1.0.0
  * @param int $id Product id
  * @return mixed
  * @author Francesco Licandro <*****@*****.**>
  */
 function yith_waitlist_get_registered_users($id)
 {
     $waitlist = yith_waitlist_get($id);
     $users = array();
     if (is_array($waitlist)) {
         foreach ($waitlist as $key => $email) {
             $users[] = $email;
         }
     }
     return $users;
 }
 /**
  * Output the form according to product type and user
  *
  * @access public
  * @since 1.0.0
  * @param $product
  * @return string
  * @author Francesco Licandro <*****@*****.**>
  */
 public function the_form($product)
 {
     $html = '';
     // control if variation is in excluded list
     if ($product->is_in_stock()) {
         return $html;
     }
     $user = wp_get_current_user();
     $product_type = $product->product_type;
     $product_id = $product_type == 'simple' ? $product->id : $product->variation_id;
     $waitlist = yith_waitlist_get($product_id);
     $url = $product_type == 'simple' ? get_permalink($product->id) : get_permalink($product->parent->id);
     // set query
     $url = add_query_arg(YITH_WCWTL_META, $product_id, $url);
     $url = wp_nonce_url($url, 'action_waitlist');
     $url = add_query_arg(YITH_WCWTL_META . '-action', 'register', $url);
     //add message
     $html .= '<div id="yith-wcwtl-output"><p class="yith-wcwtl-msg">' . get_option('yith-wcwtl-form-message') . '</p>';
     // get buttons label from options
     $label_button_add = get_option('yith-wcwtl-button-add-label');
     $label_button_leave = get_option('yith-wcwtl-button-leave-label');
     if ($product_type == 'simple' && !$user->exists()) {
         $html .= '<form method="post" action="' . esc_url($url) . '">';
         $html .= '<label for="yith-wcwtl-email">' . __('Email Address', 'yith-woocommerce-waiting-list') . '<input type="email" name="yith-wcwtl-email" id="yith-wcwtl-email" /></label>';
         $html .= '<input type="submit" value="' . $label_button_add . '" class="button alt" />';
         $html .= '</form>';
     } elseif ($product_type == 'variation' && !$user->exists()) {
         $html .= '<input type="email" name="yith-wcwtl-email" id="yith-wcwtl-email" class="wcwtl-variation" />';
         $html .= '<a href="' . esc_url($url) . '" class="button alt">' . $label_button_add . '</a>';
     } elseif (is_array($waitlist) && yith_waitlist_user_is_register($user->user_email, $waitlist)) {
         $url = add_query_arg(YITH_WCWTL_META . '-action', 'leave', $url);
         $html .= '<a href="' . esc_url($url) . '" class="button button-leave alt">' . $label_button_leave . '</a>';
     } else {
         $html .= '<a href="' . esc_url($url) . '" class="button alt">' . $label_button_add . '</a>';
     }
     $html .= '</div>';
     return $html;
 }