Plugin Directory

Changeset 1441835


Ignore:
Timestamp:
06/22/2016 03:03:00 PM (10 years ago)
Author:
wizcoder
Message:

Release 1.0.2, see readme.txt for the changelog.

Location:
wc-simple-waiting-list
Files:
12 added
2 deleted
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wc-simple-waiting-list/tags/1.0.2/admin/class-wc-simple-waiting-list-admin.php

    r1434483 r1441835  
    107107        require_once( 'includes/class-wc-simple-waiting-list-email.php' );
    108108        $emails['Wc_Simple_Waiting_List_Email'] =  new Wc_Simple_Waiting_List_Email();
    109         error_log(print_r($emails, true));
    110109        return $emails;
    111110    }
     
    186185        if( is_array( $waiting_list ) ) {
    187186            foreach( $waiting_list as $key => $user_email ) {
    188                 error_log('wc_simple_waiting_list_email_send->' . $product_id . ',  ' . $user_email);
    189187                do_action('class_wc_simple_waiting_list_email_send', $product_id,  $user_email);
    190188            }
     
    193191    }
    194192       
    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                         Product
    204                      </div>
    205                       <div id="divCell">
    206                      No. of People on Waiting List</td></tr>
    207                       </div>
    208                 </div>
    209              <?php
    210              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     <?php
    225     }
    226 
    227193    public function wc_simple_waiting_list_page() {
    228194        $results = $this->get_meta_values( $this->metakey );
     
    231197            <h1><?php _e( 'Waiting List', 'wc-simple-waiting-list' ); ?></h1>
    232198            <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>
    257225            </div>
     226        </div>
    258227    <?php
    259228    }
  • wc-simple-waiting-list/tags/1.0.2/admin/css/wc-simple-waiting-list-admin.css

    r1434483 r1441835  
    44 */
    55
     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  
    180180        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
    181181        $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' );
    182186        $this->loader->add_action( 'woocommerce_before_single_product', $plugin_public, 'wc_simple_waiting_list_box' );
    183187    }
  • wc-simple-waiting-list/tags/1.0.2/public/class-wc-simple-waiting-list-public.php

    r1434483 r1441835  
    101101
    102102        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            ); 
    104111    }
    105112
     
    146153            return true;
    147154        }
    148 
    149155        $waiting_list[] = $user_email;
    150156        update_post_meta($product_id, $this->metakey, $waiting_list);
     157
    151158        return true;
    152159    }
     
    161168            return true;
    162169        }
    163 
    164170        $new_waiting_list = array_diff($waiting_list, array($user_email));
    165171        update_post_meta($product_id, $this->metakey, $new_waiting_list);
     
    167173    }
    168174
    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   
    203196
    204197    public function wc_simple_waiting_list_box_details($html, $availability, $_product = false ) {
     
    217210        $product_id     = ( $product_type == 'simple' ) ? $_product->id : $_product->variation_id;
    218211       
    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">';
    232213       
    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;                     
    244227    }
    245228
  • wc-simple-waiting-list/tags/1.0.2/public/js/wc-simple-waiting-list-public.js

    r1434483 r1441835  
    22    'use strict';
    33
    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() {
    315
     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    }
    3289})( jQuery );
  • wc-simple-waiting-list/tags/1.0.2/readme.txt

    r1434483 r1441835  
    55Requires at least: 4.5
    66Tested up to: 4.5.2
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
    1010
    11 A woocommerce extension to allow out of sotck products to have a waiting list for registered and non-registered users.
     11A woocommerce extension to allow out of stock products to have a waiting list for registered and non-registered users.
    1212
    1313== Description ==
     
    3232
    3333== 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 =
    3539* Use Wordpress Plugin boilerplate.
    3640* Better css table.
  • wc-simple-waiting-list/tags/1.0.2/wc-simple-waiting-list.php

    r1434483 r1441835  
    1717 * Plugin URI:        http://imakeplugins.com/wc-simple-waiting-list/
    1818 * Description:       This is a short description of what the plugin does. It's displayed in the WordPress admin area.
    19  * Version:           1.0.1
     19 * Version:           1.0.2
    2020 * Author:            Bob Ong
    2121 * Author URI:        http://imakeplugins.com
     
    3131}
    3232
     33if ( ! defined( 'WC_SIMPLE_WAITING_LIST_MAIN_PATH' ) ){
     34    define( 'WC_SIMPLE_WAITING_LIST_MAIN_PATH', plugin_dir_path( __FILE__ )  );
     35}
    3336/**
    3437 * The code that runs during plugin activation.
  • wc-simple-waiting-list/trunk/admin/class-wc-simple-waiting-list-admin.php

    r1434483 r1441835  
    107107        require_once( 'includes/class-wc-simple-waiting-list-email.php' );
    108108        $emails['Wc_Simple_Waiting_List_Email'] =  new Wc_Simple_Waiting_List_Email();
    109         error_log(print_r($emails, true));
    110109        return $emails;
    111110    }
     
    186185        if( is_array( $waiting_list ) ) {
    187186            foreach( $waiting_list as $key => $user_email ) {
    188                 error_log('wc_simple_waiting_list_email_send->' . $product_id . ',  ' . $user_email);
    189187                do_action('class_wc_simple_waiting_list_email_send', $product_id,  $user_email);
    190188            }
     
    193191    }
    194192       
    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                         Product
    204                      </div>
    205                       <div id="divCell">
    206                      No. of People on Waiting List</td></tr>
    207                       </div>
    208                 </div>
    209              <?php
    210              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     <?php
    225     }
    226 
    227193    public function wc_simple_waiting_list_page() {
    228194        $results = $this->get_meta_values( $this->metakey );
     
    231197            <h1><?php _e( 'Waiting List', 'wc-simple-waiting-list' ); ?></h1>
    232198            <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>
    257225            </div>
     226        </div>
    258227    <?php
    259228    }
  • wc-simple-waiting-list/trunk/admin/css/wc-simple-waiting-list-admin.css

    r1434483 r1441835  
    44 */
    55
     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  
    180180        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
    181181        $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' );
    182186        $this->loader->add_action( 'woocommerce_before_single_product', $plugin_public, 'wc_simple_waiting_list_box' );
    183187    }
  • wc-simple-waiting-list/trunk/public/class-wc-simple-waiting-list-public.php

    r1434483 r1441835  
    101101
    102102        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            ); 
    104111    }
    105112
     
    146153            return true;
    147154        }
    148 
    149155        $waiting_list[] = $user_email;
    150156        update_post_meta($product_id, $this->metakey, $waiting_list);
     157
    151158        return true;
    152159    }
     
    161168            return true;
    162169        }
    163 
    164170        $new_waiting_list = array_diff($waiting_list, array($user_email));
    165171        update_post_meta($product_id, $this->metakey, $new_waiting_list);
     
    167173    }
    168174
    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   
    203196
    204197    public function wc_simple_waiting_list_box_details($html, $availability, $_product = false ) {
     
    217210        $product_id     = ( $product_type == 'simple' ) ? $_product->id : $_product->variation_id;
    218211       
    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">';
    232213       
    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;                     
    244227    }
    245228
  • wc-simple-waiting-list/trunk/public/js/wc-simple-waiting-list-public.js

    r1434483 r1441835  
    22    'use strict';
    33
    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() {
    315
     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    }
    3289})( jQuery );
  • wc-simple-waiting-list/trunk/readme.txt

    r1434483 r1441835  
    55Requires at least: 4.5
    66Tested up to: 4.5.2
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
    1010
    11 A woocommerce extension to allow out of sotck products to have a waiting list for registered and non-registered users.
     11A woocommerce extension to allow out of stock products to have a waiting list for registered and non-registered users.
    1212
    1313== Description ==
     
    3232
    3333== 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 =
    3539* Use Wordpress Plugin boilerplate.
    3640* Better css table.
  • wc-simple-waiting-list/trunk/wc-simple-waiting-list.php

    r1434483 r1441835  
    1717 * Plugin URI:        http://imakeplugins.com/wc-simple-waiting-list/
    1818 * Description:       This is a short description of what the plugin does. It's displayed in the WordPress admin area.
    19  * Version:           1.0.1
     19 * Version:           1.0.2
    2020 * Author:            Bob Ong
    2121 * Author URI:        http://imakeplugins.com
     
    3131}
    3232
     33if ( ! defined( 'WC_SIMPLE_WAITING_LIST_MAIN_PATH' ) ){
     34    define( 'WC_SIMPLE_WAITING_LIST_MAIN_PATH', plugin_dir_path( __FILE__ )  );
     35}
    3336/**
    3437 * The code that runs during plugin activation.
Note: See TracChangeset for help on using the changeset viewer.