Changeset 1441835
- Timestamp:
- 06/22/2016 03:03:00 PM (10 years ago)
- Location:
- wc-simple-waiting-list
- Files:
-
- 12 added
- 2 deleted
- 14 edited
- 1 copied
-
tags/1.0.2 (copied) (copied from wc-simple-waiting-list/trunk)
-
tags/1.0.2/admin/class-wc-simple-waiting-list-admin.php (modified) (4 diffs)
-
tags/1.0.2/admin/class-wc-simple-waiting-list-email.php (added)
-
tags/1.0.2/admin/css/wc-simple-waiting-list-admin.css (modified) (1 diff)
-
tags/1.0.2/admin/includes (deleted)
-
tags/1.0.2/includes/class-wc-simple-waiting-list.php (modified) (1 diff)
-
tags/1.0.2/public/class-wc-simple-waiting-list-public.php (modified) (5 diffs)
-
tags/1.0.2/public/js/wc-simple-waiting-list-public.js (modified) (1 diff)
-
tags/1.0.2/readme.txt (modified) (2 diffs)
-
tags/1.0.2/wc-simple-waiting-list.php (modified) (2 diffs)
-
tags/1.0.2/woocommerce (added)
-
tags/1.0.2/woocommerce/emails (added)
-
tags/1.0.2/woocommerce/emails/plain (added)
-
tags/1.0.2/woocommerce/emails/plain/waiting-list.php (added)
-
tags/1.0.2/woocommerce/emails/waiting-list.php (added)
-
trunk/admin/class-wc-simple-waiting-list-admin.php (modified) (4 diffs)
-
trunk/admin/class-wc-simple-waiting-list-email.php (added)
-
trunk/admin/css/wc-simple-waiting-list-admin.css (modified) (1 diff)
-
trunk/admin/includes (deleted)
-
trunk/includes/class-wc-simple-waiting-list.php (modified) (1 diff)
-
trunk/public/class-wc-simple-waiting-list-public.php (modified) (5 diffs)
-
trunk/public/js/wc-simple-waiting-list-public.js (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/wc-simple-waiting-list.php (modified) (2 diffs)
-
trunk/woocommerce (added)
-
trunk/woocommerce/emails (added)
-
trunk/woocommerce/emails/plain (added)
-
trunk/woocommerce/emails/plain/waiting-list.php (added)
-
trunk/woocommerce/emails/waiting-list.php (added)
Legend:
- Unmodified
- Added
- Removed
-
wc-simple-waiting-list/tags/1.0.2/admin/class-wc-simple-waiting-list-admin.php
r1434483 r1441835 107 107 require_once( 'includes/class-wc-simple-waiting-list-email.php' ); 108 108 $emails['Wc_Simple_Waiting_List_Email'] = new Wc_Simple_Waiting_List_Email(); 109 error_log(print_r($emails, true));110 109 return $emails; 111 110 } … … 186 185 if( is_array( $waiting_list ) ) { 187 186 foreach( $waiting_list as $key => $user_email ) { 188 error_log('wc_simple_waiting_list_email_send->' . $product_id . ', ' . $user_email);189 187 do_action('class_wc_simple_waiting_list_email_send', $product_id, $user_email); 190 188 } … … 193 191 } 194 192 195 public function wc_simple_waiting_list_page_old() {196 $results = $this->get_meta_values( $this->metakey );197 ?>198 <div class="wrap">199 <h2><?php esc_html_e('Waiting List', 'wc-simple-waiting-list') ?></h2>200 <div id="divTable">201 <div id="divRowHeader">202 <div id="divCell">203 Product204 </div>205 <div id="divCell">206 No. of People on Waiting List</td></tr>207 </div>208 </div>209 <?php210 foreach ($results as $data) {211 $product = new WC_product($data->ID);212 echo '<div id="divRow">213 <div id="divCell">';214 echo $product->post->post_title;215 echo '</div>216 <div id="divCell">';217 echo count(unserialize($data->Value));218 echo '</div>219 </div>';220 }221 ?>222 </div>223 224 <?php225 }226 227 193 public function wc_simple_waiting_list_page() { 228 194 $results = $this->get_meta_values( $this->metakey ); … … 231 197 <h1><?php _e( 'Waiting List', 'wc-simple-waiting-list' ); ?></h1> 232 198 <br class="clear" /> 233 <div id="col-container"> 234 <div class="col-wrap"> 235 <table class="widefat attributes-table wp-list-table ui-sortable" style="width:100%"> 236 <thead> 237 <tr> 238 <th scope="col"><?php _e( 'Product', 'wc-simple-waiting-list' ); ?></th> 239 <th scope="col"><?php _e( 'No. of People Joined', 'wc-simple-waiting-list' ); ?></th> 240 </tr> 241 </thead> 242 <tbody> 243 <?php 244 foreach ($results as $data) { 245 $product = new WC_product($data->ID); 246 echo '<tr><td>'; 247 echo $product->post->post_title; 248 echo '</td><td>'; 249 echo count(unserialize($data->Value)); 250 echo '</td></tr>'; 251 } 252 ?> 253 </tbody> 254 </table> 255 </div> 256 </div> 199 <div id="reminders"> 200 <table class="shop_table shop_table_responsive"> 201 <thead> 202 <tr> 203 <th scope="col"><?php _e( 'Product', 'wc-simple-waiting-list' ); ?></th> 204 <th scope="col"><?php _e( 'No. of People Joined', 'wc-simple-waiting-list' ); ?></th> 205 <th scope="col"><?php _e( 'Emails', 'wc-simple-waiting-list' ); ?></th> 206 </tr> 207 </thead> 208 <tbody> 209 <?php 210 foreach ($results as $data) { 211 $product = new WC_product($data->ID); 212 echo '<tr><td>'; 213 echo $product->post->post_title; 214 echo '</td><td>'; 215 echo count(unserialize($data->Value)); 216 echo '</td><td>'; 217 foreach (unserialize($data->Value) as $emails) { 218 echo $emails . '<br>'; 219 } 220 echo '</td></tr>'; 221 } 222 ?> 223 </tbody> 224 </table> 257 225 </div> 226 </div> 258 227 <?php 259 228 } -
wc-simple-waiting-list/tags/1.0.2/admin/css/wc-simple-waiting-list-admin.css
r1434483 r1441835 4 4 */ 5 5 6 #reminders table.shop_table { 7 border: 1px solid rgba(0, 0, 0, .1); 8 margin: 0 -1px 24px 0; 9 text-align: left; 10 width: 100%; 11 border-collapse: separate; 12 border-radius: 5px; 13 } 14 #reminders table.shop_table th { 15 font-weight: 700; 16 padding: 9px 12px; 17 background-color: #ccc; 18 } 19 #reminders table.shop_table td { 20 border-top: 1px solid rgba(0, 0, 0, .1); 21 padding: 6px 12px; 22 vertical-align: middle; 23 } 24 #reminders table.shop_table td small { 25 font-weight: 400; 26 } 27 #reminders table.shop_table tbody:first-child tr:first-child td, #reminders table.shop_table tbody:first-child tr:first-child th { 28 border-top: 0; 29 } 30 #reminders table.shop_table tbody th, #reminders table.shop_table tfoot td, #reminders table.shop_table tfoot th { 31 font-weight: 700; 32 border-top: 1px solid rgba(0, 0, 0, .1); 33 } -
wc-simple-waiting-list/tags/1.0.2/includes/class-wc-simple-waiting-list.php
r1434483 r1441835 180 180 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); 181 181 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); 182 $this->loader->add_action( 'wp_ajax_wc_simple_waiting_list_user_add', $plugin_public, 'wc_simple_waiting_list_add_user' ); 183 $this->loader->add_action( 'wp_ajax_nopriv_wc_simple_waiting_list_user_add', $plugin_public, 'wc_simple_waiting_list_add_user' ); 184 $this->loader->add_action( 'wp_ajax_wc_simple_waiting_list_user_del', $plugin_public, 'wc_simple_waiting_list_del_user' ); 185 $this->loader->add_action( 'wp_ajax_nopriv_wc_simple_waiting_list_user_del', $plugin_public, 'wc_simple_waiting_list_del_user' ); 182 186 $this->loader->add_action( 'woocommerce_before_single_product', $plugin_public, 'wc_simple_waiting_list_box' ); 183 187 } -
wc-simple-waiting-list/tags/1.0.2/public/class-wc-simple-waiting-list-public.php
r1434483 r1441835 101 101 102 102 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-simple-waiting-list-public.js', array( 'jquery' ), $this->version, false ); 103 103 wp_localize_script( $this->plugin_name, 'wc_simple_waiting_list_vars', 104 array( 105 'ajaxurl' => admin_url( 'admin-ajax.php' ), 106 'nonce' => wp_create_nonce('wc-simple-waiting-list-nonce'), 107 'already_inserted_message' => __('You are already on the list.', 'wc_simple_waiting_list'), 108 'error_message' => __('Sorry, there was a problem processing your request.', 'wc_simple_waiting_list') 109 ) 110 ); 104 111 } 105 112 … … 146 153 return true; 147 154 } 148 149 155 $waiting_list[] = $user_email; 150 156 update_post_meta($product_id, $this->metakey, $waiting_list); 157 151 158 return true; 152 159 } … … 161 168 return true; 162 169 } 163 164 170 $new_waiting_list = array_diff($waiting_list, array($user_email)); 165 171 update_post_meta($product_id, $this->metakey, $new_waiting_list); … … 167 173 } 168 174 169 public function wc_simple_waiting_list_box_join() 170 { 171 ?> 172 <div class="wrap"> 173 <form id="mywaitlistform" method="post" action="" class="form" > 174 <input type="submit" name="save" value="Join Waiting List"> 175 </form> 176 </div> 177 <?php 178 } 179 180 public function wc_simple_waiting_list_box_join_unreg() 181 { 182 ?> 183 <div class="wrap"> 184 <form id="mywaitlistform" method="post" action="" class="form" > 185 <input type="email" name="emailaddr" id="emailaddr" value="" placeholder="You email address" /><br /><br /> 186 <input type="submit" name="save" value="Join Waiting List"> 187 </form> 188 </div> 189 <?php 190 } 191 192 public function wc_simple_waiting_list_box_leave($user_email) 193 { 194 ?> 195 <div class="wrap"> 196 <form id="mywaitlistform" method="post" action="" class="form" > 197 <input type="hidden" name="emailaddr" id="emailaddr" value=" <?php echo $user_email ?>" placeholder="You email address" /><br /><br /> 198 <input type="submit" name="remove" value="Leave Waiting List"> 199 </form> 200 </div> 201 <?php 202 } 175 public function wc_simple_waiting_list_add_user(){ 176 if ( isset( $_POST['user_email'] ) && isset( $_POST['product_id'] ) && wp_verify_nonce($_POST['wc_simple_waiting_list_nonce'], 'wc-simple-waiting-list-nonce') ) { 177 if ($this->wc_simple_waiting_list_register( $_POST['user_email'], $_POST['product_id'] )) 178 echo 'success'; 179 else 180 echo 'fail'; 181 } 182 die(); 183 } 184 185 public function wc_simple_waiting_list_del_user(){ 186 if ( isset( $_POST['user_email'] ) && isset( $_POST['product_id'] ) && wp_verify_nonce($_POST['wc_simple_waiting_list_nonce'], 'wc-simple-waiting-list-nonce') ) { 187 if ($this->wc_simple_waiting_list_deregister( $_POST['user_email'], $_POST['product_id'] )) 188 echo 'success'; 189 else 190 echo 'fail'; 191 } 192 die(); 193 } 194 195 203 196 204 197 public function wc_simple_waiting_list_box_details($html, $availability, $_product = false ) { … … 217 210 $product_id = ( $product_type == 'simple' ) ? $_product->id : $_product->variation_id; 218 211 219 $url = ( $product_type == 'simple' ) ? get_permalink( $_product->id ) : get_permalink( $_product->parent->id ); 220 221 $user_email = ( isset( $_POST[ 'emailaddr' ] ) ) ? $_POST[ 'emailaddr' ] : $user->user_email; 222 $user_email = str_replace(' ', '', $user_email ); 223 224 if ( isset($_POST['save']) ) { 225 $result = $this->wc_simple_waiting_list_register( $user_email, $product_id ); 226 } 227 else if ( isset($_POST['remove']) ) 228 { 229 $result = $this->wc_simple_waiting_list_deregister( $user_email, $product_id ); 230 } 231 212 $box = '<div class="wrap">'; 232 213 233 if ($this->wc_simple_waiting_list_isregister( $user_email, $product_id )) { 234 $this->wc_simple_waiting_list_box_leave( $user_email ); 235 return; 236 } 237 238 if ( $user->exists() ) { 239 $this->wc_simple_waiting_list_box_join(); 240 } 241 else { 242 $this->wc_simple_waiting_list_box_join_unreg(); 243 } 214 $addstyle = "display:none"; 215 $removestyle = "display:none"; 216 if ($this->wc_simple_waiting_list_isregister( $user->user_email, $product_id )) 217 $removestyle = "display:block"; 218 else 219 $addstyle = "display:block"; 220 221 $box .='<input type="submit" name="remove" id="remove" style="'. $removestyle . '" data-user-email="'. $user->user_email . '" data-product-id="'. $product_id . '" value="Leave Waiting List">'; 222 if ( ! $user->exists() ) 223 $box .= '<input type="text" name="emailaddr" id="emailaddr" style="'. $addstyle . '" placeholder="You email address" /><br /><br />'; 224 $box .= '<input type="submit" name="save" id="save" style="'. $addstyle . '" data-user-email="'. $user->user_email . '" data-product-id="'. $product_id . '" value="Join Waiting List">'; 225 $box .= '</div>'; 226 echo $box; 244 227 } 245 228 -
wc-simple-waiting-list/tags/1.0.2/public/js/wc-simple-waiting-list-public.js
r1434483 r1441835 2 2 'use strict'; 3 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 4 $(function() { 31 5 6 $("#save").live('click',function(){ 7 var product_id = $(this).data('product-id'); 8 var user_email = $("#emailaddr").val(); 9 10 if ($.trim(user_email).length == 0) 11 user_email = $(this).data('user-email'); 12 13 if ($.trim(user_email).length == 0 || $.trim(product_id).length == 0) 14 { 15 alert('An Error Has Occur!'); 16 return false; 17 } 18 19 if (!validateEmail(user_email)) { 20 alert('Invalid Email Address'); 21 return false; 22 } 23 24 $("#emailaddr").hide() 25 $("#save").hide(); 26 27 var post_data = { 28 action: 'wc_simple_waiting_list_user_add', 29 product_id: product_id, 30 user_email: user_email, 31 wc_simple_waiting_list_nonce: wc_simple_waiting_list_vars.nonce 32 }; 33 34 $.post(wc_simple_waiting_list_vars.ajaxurl, post_data, function(response) { 35 if(response == 'success') { 36 $("#remove").show() 37 } else { 38 $("#emailaddr").show() 39 $("#save").show(); 40 alert(wc_simple_waiting_list_vars.error_message); 41 } 42 }); 43 return false; 44 }); 45 46 $("#remove").live('click',function(){ 47 var product_id = $(this).data('product-id'); 48 var user_email = $("#emailaddr").val(); 49 50 if ($.trim(user_email).length == 0) 51 user_email = $(this).data('user-email'); 52 53 if ($.trim(user_email).length == 0 || $.trim(product_id).length == 0) 54 { 55 alert('An Error Has Occur!'); 56 return false; 57 } 58 $("#remove").hide() 59 60 var post_data = { 61 action: 'wc_simple_waiting_list_user_del', 62 product_id: product_id, 63 user_email: user_email, 64 wc_simple_waiting_list_nonce: wc_simple_waiting_list_vars.nonce 65 }; 66 67 $.post(wc_simple_waiting_list_vars.ajaxurl, post_data, function(response) { 68 if(response == 'success') { 69 $("#save").show() 70 $("#emailaddr").show(); 71 } else { 72 $("#remove").show() 73 alert(wc_simple_waiting_list_vars.error_message); 74 } 75 }); 76 return false; 77 }); 78 }); 79 80 function validateEmail(sEmail) { 81 var filter = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; 82 if (filter.test(sEmail)) { 83 return true; 84 } 85 else { 86 return false; 87 } 88 } 32 89 })( jQuery ); -
wc-simple-waiting-list/tags/1.0.2/readme.txt
r1434483 r1441835 5 5 Requires at least: 4.5 6 6 Tested up to: 4.5.2 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html 10 10 11 A woocommerce extension to allow out of s otck products to have a waiting list for registered and non-registered users.11 A woocommerce extension to allow out of stock products to have a waiting list for registered and non-registered users. 12 12 13 13 == Description == … … 32 32 33 33 == Changelog == 34 = 1.0.1 - 29/01/2016 = 34 = 1.0.2 - 22/06/2016 = 35 * add ajax. 36 * add email to admin list table 37 38 = 1.0.1 - 29/05/2016 = 35 39 * Use Wordpress Plugin boilerplate. 36 40 * Better css table. -
wc-simple-waiting-list/tags/1.0.2/wc-simple-waiting-list.php
r1434483 r1441835 17 17 * Plugin URI: http://imakeplugins.com/wc-simple-waiting-list/ 18 18 * Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area. 19 * Version: 1.0. 119 * Version: 1.0.2 20 20 * Author: Bob Ong 21 21 * Author URI: http://imakeplugins.com … … 31 31 } 32 32 33 if ( ! defined( 'WC_SIMPLE_WAITING_LIST_MAIN_PATH' ) ){ 34 define( 'WC_SIMPLE_WAITING_LIST_MAIN_PATH', plugin_dir_path( __FILE__ ) ); 35 } 33 36 /** 34 37 * The code that runs during plugin activation. -
wc-simple-waiting-list/trunk/admin/class-wc-simple-waiting-list-admin.php
r1434483 r1441835 107 107 require_once( 'includes/class-wc-simple-waiting-list-email.php' ); 108 108 $emails['Wc_Simple_Waiting_List_Email'] = new Wc_Simple_Waiting_List_Email(); 109 error_log(print_r($emails, true));110 109 return $emails; 111 110 } … … 186 185 if( is_array( $waiting_list ) ) { 187 186 foreach( $waiting_list as $key => $user_email ) { 188 error_log('wc_simple_waiting_list_email_send->' . $product_id . ', ' . $user_email);189 187 do_action('class_wc_simple_waiting_list_email_send', $product_id, $user_email); 190 188 } … … 193 191 } 194 192 195 public function wc_simple_waiting_list_page_old() {196 $results = $this->get_meta_values( $this->metakey );197 ?>198 <div class="wrap">199 <h2><?php esc_html_e('Waiting List', 'wc-simple-waiting-list') ?></h2>200 <div id="divTable">201 <div id="divRowHeader">202 <div id="divCell">203 Product204 </div>205 <div id="divCell">206 No. of People on Waiting List</td></tr>207 </div>208 </div>209 <?php210 foreach ($results as $data) {211 $product = new WC_product($data->ID);212 echo '<div id="divRow">213 <div id="divCell">';214 echo $product->post->post_title;215 echo '</div>216 <div id="divCell">';217 echo count(unserialize($data->Value));218 echo '</div>219 </div>';220 }221 ?>222 </div>223 224 <?php225 }226 227 193 public function wc_simple_waiting_list_page() { 228 194 $results = $this->get_meta_values( $this->metakey ); … … 231 197 <h1><?php _e( 'Waiting List', 'wc-simple-waiting-list' ); ?></h1> 232 198 <br class="clear" /> 233 <div id="col-container"> 234 <div class="col-wrap"> 235 <table class="widefat attributes-table wp-list-table ui-sortable" style="width:100%"> 236 <thead> 237 <tr> 238 <th scope="col"><?php _e( 'Product', 'wc-simple-waiting-list' ); ?></th> 239 <th scope="col"><?php _e( 'No. of People Joined', 'wc-simple-waiting-list' ); ?></th> 240 </tr> 241 </thead> 242 <tbody> 243 <?php 244 foreach ($results as $data) { 245 $product = new WC_product($data->ID); 246 echo '<tr><td>'; 247 echo $product->post->post_title; 248 echo '</td><td>'; 249 echo count(unserialize($data->Value)); 250 echo '</td></tr>'; 251 } 252 ?> 253 </tbody> 254 </table> 255 </div> 256 </div> 199 <div id="reminders"> 200 <table class="shop_table shop_table_responsive"> 201 <thead> 202 <tr> 203 <th scope="col"><?php _e( 'Product', 'wc-simple-waiting-list' ); ?></th> 204 <th scope="col"><?php _e( 'No. of People Joined', 'wc-simple-waiting-list' ); ?></th> 205 <th scope="col"><?php _e( 'Emails', 'wc-simple-waiting-list' ); ?></th> 206 </tr> 207 </thead> 208 <tbody> 209 <?php 210 foreach ($results as $data) { 211 $product = new WC_product($data->ID); 212 echo '<tr><td>'; 213 echo $product->post->post_title; 214 echo '</td><td>'; 215 echo count(unserialize($data->Value)); 216 echo '</td><td>'; 217 foreach (unserialize($data->Value) as $emails) { 218 echo $emails . '<br>'; 219 } 220 echo '</td></tr>'; 221 } 222 ?> 223 </tbody> 224 </table> 257 225 </div> 226 </div> 258 227 <?php 259 228 } -
wc-simple-waiting-list/trunk/admin/css/wc-simple-waiting-list-admin.css
r1434483 r1441835 4 4 */ 5 5 6 #reminders table.shop_table { 7 border: 1px solid rgba(0, 0, 0, .1); 8 margin: 0 -1px 24px 0; 9 text-align: left; 10 width: 100%; 11 border-collapse: separate; 12 border-radius: 5px; 13 } 14 #reminders table.shop_table th { 15 font-weight: 700; 16 padding: 9px 12px; 17 background-color: #ccc; 18 } 19 #reminders table.shop_table td { 20 border-top: 1px solid rgba(0, 0, 0, .1); 21 padding: 6px 12px; 22 vertical-align: middle; 23 } 24 #reminders table.shop_table td small { 25 font-weight: 400; 26 } 27 #reminders table.shop_table tbody:first-child tr:first-child td, #reminders table.shop_table tbody:first-child tr:first-child th { 28 border-top: 0; 29 } 30 #reminders table.shop_table tbody th, #reminders table.shop_table tfoot td, #reminders table.shop_table tfoot th { 31 font-weight: 700; 32 border-top: 1px solid rgba(0, 0, 0, .1); 33 } -
wc-simple-waiting-list/trunk/includes/class-wc-simple-waiting-list.php
r1434483 r1441835 180 180 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); 181 181 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); 182 $this->loader->add_action( 'wp_ajax_wc_simple_waiting_list_user_add', $plugin_public, 'wc_simple_waiting_list_add_user' ); 183 $this->loader->add_action( 'wp_ajax_nopriv_wc_simple_waiting_list_user_add', $plugin_public, 'wc_simple_waiting_list_add_user' ); 184 $this->loader->add_action( 'wp_ajax_wc_simple_waiting_list_user_del', $plugin_public, 'wc_simple_waiting_list_del_user' ); 185 $this->loader->add_action( 'wp_ajax_nopriv_wc_simple_waiting_list_user_del', $plugin_public, 'wc_simple_waiting_list_del_user' ); 182 186 $this->loader->add_action( 'woocommerce_before_single_product', $plugin_public, 'wc_simple_waiting_list_box' ); 183 187 } -
wc-simple-waiting-list/trunk/public/class-wc-simple-waiting-list-public.php
r1434483 r1441835 101 101 102 102 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wc-simple-waiting-list-public.js', array( 'jquery' ), $this->version, false ); 103 103 wp_localize_script( $this->plugin_name, 'wc_simple_waiting_list_vars', 104 array( 105 'ajaxurl' => admin_url( 'admin-ajax.php' ), 106 'nonce' => wp_create_nonce('wc-simple-waiting-list-nonce'), 107 'already_inserted_message' => __('You are already on the list.', 'wc_simple_waiting_list'), 108 'error_message' => __('Sorry, there was a problem processing your request.', 'wc_simple_waiting_list') 109 ) 110 ); 104 111 } 105 112 … … 146 153 return true; 147 154 } 148 149 155 $waiting_list[] = $user_email; 150 156 update_post_meta($product_id, $this->metakey, $waiting_list); 157 151 158 return true; 152 159 } … … 161 168 return true; 162 169 } 163 164 170 $new_waiting_list = array_diff($waiting_list, array($user_email)); 165 171 update_post_meta($product_id, $this->metakey, $new_waiting_list); … … 167 173 } 168 174 169 public function wc_simple_waiting_list_box_join() 170 { 171 ?> 172 <div class="wrap"> 173 <form id="mywaitlistform" method="post" action="" class="form" > 174 <input type="submit" name="save" value="Join Waiting List"> 175 </form> 176 </div> 177 <?php 178 } 179 180 public function wc_simple_waiting_list_box_join_unreg() 181 { 182 ?> 183 <div class="wrap"> 184 <form id="mywaitlistform" method="post" action="" class="form" > 185 <input type="email" name="emailaddr" id="emailaddr" value="" placeholder="You email address" /><br /><br /> 186 <input type="submit" name="save" value="Join Waiting List"> 187 </form> 188 </div> 189 <?php 190 } 191 192 public function wc_simple_waiting_list_box_leave($user_email) 193 { 194 ?> 195 <div class="wrap"> 196 <form id="mywaitlistform" method="post" action="" class="form" > 197 <input type="hidden" name="emailaddr" id="emailaddr" value=" <?php echo $user_email ?>" placeholder="You email address" /><br /><br /> 198 <input type="submit" name="remove" value="Leave Waiting List"> 199 </form> 200 </div> 201 <?php 202 } 175 public function wc_simple_waiting_list_add_user(){ 176 if ( isset( $_POST['user_email'] ) && isset( $_POST['product_id'] ) && wp_verify_nonce($_POST['wc_simple_waiting_list_nonce'], 'wc-simple-waiting-list-nonce') ) { 177 if ($this->wc_simple_waiting_list_register( $_POST['user_email'], $_POST['product_id'] )) 178 echo 'success'; 179 else 180 echo 'fail'; 181 } 182 die(); 183 } 184 185 public function wc_simple_waiting_list_del_user(){ 186 if ( isset( $_POST['user_email'] ) && isset( $_POST['product_id'] ) && wp_verify_nonce($_POST['wc_simple_waiting_list_nonce'], 'wc-simple-waiting-list-nonce') ) { 187 if ($this->wc_simple_waiting_list_deregister( $_POST['user_email'], $_POST['product_id'] )) 188 echo 'success'; 189 else 190 echo 'fail'; 191 } 192 die(); 193 } 194 195 203 196 204 197 public function wc_simple_waiting_list_box_details($html, $availability, $_product = false ) { … … 217 210 $product_id = ( $product_type == 'simple' ) ? $_product->id : $_product->variation_id; 218 211 219 $url = ( $product_type == 'simple' ) ? get_permalink( $_product->id ) : get_permalink( $_product->parent->id ); 220 221 $user_email = ( isset( $_POST[ 'emailaddr' ] ) ) ? $_POST[ 'emailaddr' ] : $user->user_email; 222 $user_email = str_replace(' ', '', $user_email ); 223 224 if ( isset($_POST['save']) ) { 225 $result = $this->wc_simple_waiting_list_register( $user_email, $product_id ); 226 } 227 else if ( isset($_POST['remove']) ) 228 { 229 $result = $this->wc_simple_waiting_list_deregister( $user_email, $product_id ); 230 } 231 212 $box = '<div class="wrap">'; 232 213 233 if ($this->wc_simple_waiting_list_isregister( $user_email, $product_id )) { 234 $this->wc_simple_waiting_list_box_leave( $user_email ); 235 return; 236 } 237 238 if ( $user->exists() ) { 239 $this->wc_simple_waiting_list_box_join(); 240 } 241 else { 242 $this->wc_simple_waiting_list_box_join_unreg(); 243 } 214 $addstyle = "display:none"; 215 $removestyle = "display:none"; 216 if ($this->wc_simple_waiting_list_isregister( $user->user_email, $product_id )) 217 $removestyle = "display:block"; 218 else 219 $addstyle = "display:block"; 220 221 $box .='<input type="submit" name="remove" id="remove" style="'. $removestyle . '" data-user-email="'. $user->user_email . '" data-product-id="'. $product_id . '" value="Leave Waiting List">'; 222 if ( ! $user->exists() ) 223 $box .= '<input type="text" name="emailaddr" id="emailaddr" style="'. $addstyle . '" placeholder="You email address" /><br /><br />'; 224 $box .= '<input type="submit" name="save" id="save" style="'. $addstyle . '" data-user-email="'. $user->user_email . '" data-product-id="'. $product_id . '" value="Join Waiting List">'; 225 $box .= '</div>'; 226 echo $box; 244 227 } 245 228 -
wc-simple-waiting-list/trunk/public/js/wc-simple-waiting-list-public.js
r1434483 r1441835 2 2 'use strict'; 3 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 4 $(function() { 31 5 6 $("#save").live('click',function(){ 7 var product_id = $(this).data('product-id'); 8 var user_email = $("#emailaddr").val(); 9 10 if ($.trim(user_email).length == 0) 11 user_email = $(this).data('user-email'); 12 13 if ($.trim(user_email).length == 0 || $.trim(product_id).length == 0) 14 { 15 alert('An Error Has Occur!'); 16 return false; 17 } 18 19 if (!validateEmail(user_email)) { 20 alert('Invalid Email Address'); 21 return false; 22 } 23 24 $("#emailaddr").hide() 25 $("#save").hide(); 26 27 var post_data = { 28 action: 'wc_simple_waiting_list_user_add', 29 product_id: product_id, 30 user_email: user_email, 31 wc_simple_waiting_list_nonce: wc_simple_waiting_list_vars.nonce 32 }; 33 34 $.post(wc_simple_waiting_list_vars.ajaxurl, post_data, function(response) { 35 if(response == 'success') { 36 $("#remove").show() 37 } else { 38 $("#emailaddr").show() 39 $("#save").show(); 40 alert(wc_simple_waiting_list_vars.error_message); 41 } 42 }); 43 return false; 44 }); 45 46 $("#remove").live('click',function(){ 47 var product_id = $(this).data('product-id'); 48 var user_email = $("#emailaddr").val(); 49 50 if ($.trim(user_email).length == 0) 51 user_email = $(this).data('user-email'); 52 53 if ($.trim(user_email).length == 0 || $.trim(product_id).length == 0) 54 { 55 alert('An Error Has Occur!'); 56 return false; 57 } 58 $("#remove").hide() 59 60 var post_data = { 61 action: 'wc_simple_waiting_list_user_del', 62 product_id: product_id, 63 user_email: user_email, 64 wc_simple_waiting_list_nonce: wc_simple_waiting_list_vars.nonce 65 }; 66 67 $.post(wc_simple_waiting_list_vars.ajaxurl, post_data, function(response) { 68 if(response == 'success') { 69 $("#save").show() 70 $("#emailaddr").show(); 71 } else { 72 $("#remove").show() 73 alert(wc_simple_waiting_list_vars.error_message); 74 } 75 }); 76 return false; 77 }); 78 }); 79 80 function validateEmail(sEmail) { 81 var filter = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; 82 if (filter.test(sEmail)) { 83 return true; 84 } 85 else { 86 return false; 87 } 88 } 32 89 })( jQuery ); -
wc-simple-waiting-list/trunk/readme.txt
r1434483 r1441835 5 5 Requires at least: 4.5 6 6 Tested up to: 4.5.2 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html 10 10 11 A woocommerce extension to allow out of s otck products to have a waiting list for registered and non-registered users.11 A woocommerce extension to allow out of stock products to have a waiting list for registered and non-registered users. 12 12 13 13 == Description == … … 32 32 33 33 == Changelog == 34 = 1.0.1 - 29/01/2016 = 34 = 1.0.2 - 22/06/2016 = 35 * add ajax. 36 * add email to admin list table 37 38 = 1.0.1 - 29/05/2016 = 35 39 * Use Wordpress Plugin boilerplate. 36 40 * Better css table. -
wc-simple-waiting-list/trunk/wc-simple-waiting-list.php
r1434483 r1441835 17 17 * Plugin URI: http://imakeplugins.com/wc-simple-waiting-list/ 18 18 * Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area. 19 * Version: 1.0. 119 * Version: 1.0.2 20 20 * Author: Bob Ong 21 21 * Author URI: http://imakeplugins.com … … 31 31 } 32 32 33 if ( ! defined( 'WC_SIMPLE_WAITING_LIST_MAIN_PATH' ) ){ 34 define( 'WC_SIMPLE_WAITING_LIST_MAIN_PATH', plugin_dir_path( __FILE__ ) ); 35 } 33 36 /** 34 37 * The code that runs during plugin activation.
Note: See TracChangeset
for help on using the changeset viewer.