Plugin Directory

Changeset 2759778


Ignore:
Timestamp:
07/21/2022 12:08:16 PM (3 years ago)
Author:
letscms
Message:

update

Location:
pincode-based-product-price-woocommerce/trunk/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pincode-based-product-price-woocommerce/trunk/includes/class-pbdpw-hooks-function.php

    r2759776 r2759778  
    1616            $product_id = $value['product_id'];
    1717
    18             if(!empty($value['variation_id'])){
    19 
    20               $variation_id=$value['variation_id'];
    21 
    22             }else{
    23 
    24               $variation_id=0;
     18            $pincode = $_SESSION['pincode_session_for_popup'];
     19
     20            $newprice = $value['data']->get_regular_price();
     21
     22            if (!empty($pincode)) {
     23
     24                $price = $wpdb->get_var("SELECT price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $product_id . "'");
     25
     26                if (!empty($price)) {
     27
     28                    $newprice = $price;
     29
     30                }
    2531
    2632            }
    2733
    28             $pincode = $_SESSION['pincode_session_for_popup'];
    29            
    30             if(empty($value['data']->get_sale_price())){
    31 
    32               $newprice = $value['data']->get_regular_price();
    33 
    34             }else{
    35 
    36               $newprice = $value['data']->get_sale_price();
    37 
    38             }
    39 
    40             if (!empty($pincode)) {
    41 
    42                 $price = $wpdb->get_var("SELECT price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $product_id . "' AND variation_id='".$variation_id."'");
    43 
    44                 if (!empty($price)) {
    45 
    46                     $newprice = $price;
    47 
    48                 }
    49 
    50             }
    51 
    5234            $value['data']->set_price($newprice);
    5335
     
    6143{
    6244
    63     global $wpdb;
    64     $product = get_product( $post->ID );
    65    ?>
     45    global $wpdb;?>
    6646
    6747  <div class="col-md-12">
     
    8060
    8161        <th class="tb-head"><?php echo __('Price', 'bpdpw'); ?></th>
     62
     63        <th class="tb-head"><?php echo __('Quantity', 'bpdpw'); ?></th>
     64
     65        <th class="tb-head"><?php echo __('Stock', 'bpdpw'); ?></th>
    8266
    8367        <th class="tb-head"><?php echo __('action', 'bpdpw'); ?></th>
     
    9175         <input type="hidden" name="post_url" id="post_bulk_url" value="<?php echo admin_url('admin-ajax.php'); ?>">
    9276
    93          <td class="tb-body"><input type="number" name="pin_start" id="pin_start_simple" value=""></td>
    94 
    95          <td class="tb-body"><input type="number" name="pin_end" id="pin_end_simple" value=""></td>
     77         <td class="tb-body"><input type="number" name="pin_start" id="pin_start" value=""></td>
     78
     79         <td class="tb-body"><input type="number" name="pin_end" id="pin_end" value=""></td>
    9680
    9781         <td class="tb-body"><input type="text" name="bulk_price" id="bulk_price" value=""></td>
    9882
    99           <td><button class="text-center button" type="button" onclick="bpdpw_save_bulk()" ><?php echo __('Save','bpdpw');?></button></td>
     83         <td class="tb-body"><input type="number" name="bulk_qty" id="bulk_qty" value=""></td>
     84
     85         <td class="tb-body text-center"><select name='stock'  id='bulk_stock'>
     86              <option value='yes'><?php echo __('Yes', 'bpdpw'); ?></option>
     87              <option value='no'><?php echo __('No', 'bpdpw'); ?></option>
     88            </select>
     89          </td>
     90         
     91          <td><button class="text-center" type="button" onclick="bpdpw_save_bulk()" >Save</button></td>
    10092
    10193       </tr>
    102      
    10394       <tr> <td class="error_msg" colspan="4"></td></tr>
    10495      </tbody>
    10596    </table>
    106    
    10797    <script>
    10898
    10999
     100  function bpdpw_save_bulk(){
     101
     102var bulk_pincode_start=jQuery('#pin_start').val();
     103
     104var bulk_pincode_end=jQuery('#pin_end').val();
     105
     106 var bulk_price=jQuery('#bulk_price').val();
     107
     108 var bulk_quantity=jQuery('#bulk_qty').val();
     109
     110var bulk_stock=jQuery('#bulk_stock').val();
     111
     112var link = jQuery('#post_bulk_url').val();
     113
     114var product_id = jQuery('#post_ID').val();
     115
     116console.log(parseInt(bulk_pincode_start)>=parseInt(bulk_pincode_end));
     117if(parseInt(bulk_pincode_start)>parseInt(bulk_pincode_end)){
     118   jQuery('.error_msg').html('<span class="alert alert-success bg-danger" style="background:#fa5246;padding:10px 25px 10px 25px;color:white;">Please enter valid Pincode range</span>');
     119   Swal.fire({
     120        title: "Bulk Pincode",
     121        text: "Something went wrong!",
     122        icon: "error",
     123        button: "ok",
     124      });
     125   return false;
     126}
     127if(bulk_pincode_start=='' || bulk_pincode_end=='' || bulk_price=='' || bulk_quantity=='' || bulk_stock=='' ){
     128  jQuery('.error_msg').html('<span class="alert alert-success bg-danger" style="background:#fa5246;padding:10px 25px 10px 25px;color:white;">Please fill all details</span>');
     129  Swal.fire({
     130        title: "Bulk Pincode",
     131        text: "Something went wrong!",
     132        icon: "error",
     133        button: "ok",
     134      });
     135  return false;
     136}
     137
     138jQuery.ajax({
     139
     140  type: "POST",
     141
     142  url: link,
     143
     144  data:{
     145
     146  'pincode_start':bulk_pincode_start,
     147
     148  'pincode_end':bulk_pincode_end,
     149
     150  'action':'bpdpw_bulk_data_save',
     151
     152  'price':bulk_price,
     153
     154  'quantity':bulk_quantity,
     155
     156  'stock':bulk_stock,
     157
     158  'product_id':product_id,
     159
     160},
     161
     162success: function(data){
     163 
     164   
     165      Swal.fire({
     166        title: "Bulk Pincode",
     167        text: "All pincode saved successfully!",
     168        icon: "success",
     169        button: "ok",
     170      });
     171 
     172  jQuery('#bpdpw-product-pincode-price .inside').html(data);
     173
     174
     175
     176}
     177
     178});
     179
     180}
    110181
    111182      </script>
     
    114185<?php }
    115186
    116 
    117 
    118 
    119 
    120 
    121 
    122 
    123187function bpdpw_pincode_product_price_meta_box_function($post)
    124188{
    125   $product = get_product( $post->ID );
    126  
     189
    127190    global $wpdb;
    128191
    129192    $num_row = 0;
    130193
    131     $results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $post->ID . "' AND variation_id='0'");
     194    $results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $post->ID . "'");
    132195
    133196    ?>
     
    139202     <form method="POST" action="">
    140203
    141       <table  class="form-table table table-responsive">
     204      <table  class="form-table">
    142205
    143206     <thead>
     
    149212        <th class="tb-head"><?php echo __('Price', 'bpdpw'); ?></th>
    150213
     214        <th class="tb-head"><?php echo __('Quantity', 'bpdpw'); ?></th>
     215
     216        <th class="tb-head"><?php echo __('Stock', 'bpdpw'); ?></th>
     217
    151218        <th class="tb-head"><?php echo __('Action', 'bpdpw'); ?></th>
    152219
     
    161228        <?php foreach ($results as $result) {?>
    162229
    163           <tr id="row_<?php echo $num_row; ?>"><td><input type='text' value="<?php echo $result->pincode; ?>" name='pincode'  id="pincode_<?php echo $num_row; ?>"></td><td><input type='text' value="<?php echo $result->price; ?>" name='price'  id="price_<?php echo $num_row; ?>"></td><td class="row" style="display: flex;"><button class="button" type='button'  onclick='bpdpw_save(<?php echo $num_row; ?>); return true;' style="float: left"><?php echo __('Save', 'bpdpw'); ?></button><button type='button' class="button"  onclick='bpdpw_delete(<?php echo $result->id; ?>,<?php echo $result->product_id; ?>); return true;' style="float: left;"><?php echo __('Delete', 'bpdpw'); ?></button></td></tr>
     230          <tr id="row_<?php echo $num_row; ?>"><td><input type='text' value="<?php echo $result->pincode; ?>" name='pincode'  id="pincode_<?php echo $num_row; ?>"></td><td><input type='text' value="<?php echo $result->price; ?>" name='price'  id="price_<?php echo $num_row; ?>"></td><td><input type='text' name='quantity' value="<?php echo $result->quantity; ?>"  id="quantity_<?php echo $num_row; ?>"></td><td class='tb-head'><select name='stock' id="stock_<?php echo $num_row; ?>"><option value='yes' <?php echo ($result->stock == "yes") ? "selected" : ""; ?> ><?php echo __('Yes', 'bpdpw'); ?></option><option value='no' <?php echo ($result->stock == "no") ? "selected" : ""; ?>><?php echo __('No', 'bpdpw'); ?></option></select></td><td class="row" style="display: flex;"><button type='button'  onclick='bpdpw_save(<?php echo $num_row; ?>); return true;' style="float: left"><?php echo __('Save', 'bpdpw'); ?></button><button type='button'  onclick='bpdpw_delete(<?php echo $result->id; ?>,<?php echo $result->product_id; ?>); return true;' style="float: left;"><?php echo __('Delete', 'bpdpw'); ?></button></td></tr>
    164231
    165232        <?php
     
    173240        </tbody>
    174241
    175       <tfoot><td colspan="2"></td><td><button id="add_row" type="button" data-num-row="<?php echo $num_row; ?>" onclick="add(jQuery(this).attr('data-num-row'))"><?php echo __('Add', 'bpdpw'); ?></button></td>
     242      <tfoot><td colspan="4"></td><td><button id="add_row" type="button" data-num-row="<?php echo $num_row; ?>" onclick="add(jQuery(this).attr('data-num-row'))"><?php echo __('Add', 'bpdpw'); ?></button></td>
    176243
    177244  </tfoot>
     
    193260  function add(num_row){
    194261
    195     jQuery("<tr id='row_"+num_row+"'><td><input type='text' name='pincode'  id='pincode_"+num_row+"'></td><td><input type='text' name='price'  id='price_"+num_row+"'></td><td><button class='button' type='button'  onclick='bpdpw_save("+num_row+"); return true;''><?php echo __('Save', 'bpdpw'); ?></button></td></tr>").fadeIn().appendTo(".append_data");
     262
     263
     264    jQuery("<tr id='row_"+num_row+"'><td><input type='text' name='pincode'  id='pincode_"+num_row+"'></td><td><input type='text' name='price'  id='price_"+num_row+"'></td><td><input type='text' name='quantity'  id='quantity_"+num_row+"'></td><td class='tb-head'><select name='stock'  id='stock_"+num_row+"'><option value='yes'><?php echo __('Yes', 'bpdpw'); ?></option><option value='no'><?php echo __('No', 'bpdpw'); ?></option></select></td><td><button type='button'  onclick='bpdpw_save("+num_row+"); return true;''><?php echo __('Save', 'bpdpw'); ?></button></td></tr>").fadeIn().appendTo(".append_data");
    196265
    197266    num_row++;
     
    203272
    204273
     274  function bpdpw_save(num_row){
     275
     276  var pincode=jQuery('#pincode_'+num_row).val();
     277
     278   var price=jQuery('#price_'+num_row).val();
     279
     280   var quantity=jQuery('#quantity_'+num_row).val();
     281
     282  var stock=jQuery('#stock_'+num_row).val();
     283
     284  var link = jQuery('#post_url').val();
     285
     286  var product_id = jQuery('#post_ID').val();
     287
     288  jQuery.ajax({
     289
     290    type: "POST",
     291
     292    url: link,
     293
     294    data:{
     295
     296    'pincode':pincode,
     297
     298    'action':'bpdpw_data_save',
     299
     300    'price':price,
     301
     302    'quantity':quantity,
     303
     304    'stock':stock,
     305
     306    'product_id':product_id,
     307
     308  },
     309
     310  success: function(data){
     311    Swal.fire({
     312        title: "Pincode save",
     313        text: "Pincode saved successfully!",
     314        icon: "success",
     315        button: "ok",
     316      });
     317    jQuery('#bpdpw-product-pincode-price .inside').html(data);
     318
     319   //location.reload(true);
     320
     321  }
     322
     323});
     324
     325}
     326
     327
     328
     329function bpdpw_delete(id,pid){
     330
     331  var link = jQuery('#post_url').val();
     332
     333 jQuery.ajax({
     334
     335    type: "POST",
     336
     337    url: link,
     338
     339    data:{
     340
     341    'action':'bpdpw_delete_data',
     342
     343    'id':id,
     344
     345    'post_id':pid,
     346
     347  },
     348
     349  success: function(data){
     350    Swal.fire({
     351        title: "Pincode delete",
     352        text: "Pincode delete successfully!",
     353        icon: "success",
     354        button: "ok",
     355      });
     356    jQuery('#bpdpw-product-pincode-price .inside').html(data);
     357
     358  //location.reload(true);
     359
     360  }
     361
     362
     363
     364});
     365
     366}
     367
     368
     369
    205370</script>
    206371
     
    214379    global $wpdb;
    215380
    216     if(isset($_POST['variation_id']) && !empty($_POST['variation_id'])){
    217       $variation_id=$_POST['variation_id'];
    218     }else{
    219       $variation_id=0;
    220     }
    221 
    222381    $id = sanitize_text_field($_POST['id']);
    223382
     
    225384
    226385    $wpdb->query("DELETE FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE id='" . $id . "'");
    227    
     386
    228387    $p = get_post($post_id);
    229    
    230     if(!empty($variation_id)){
    231       bpdpw_pincode_variable_product_price_meta_box_function($p,$variation_id);
    232     }else{
    233       bpdpw_pincode_product_price_meta_box_function($p);
    234     }
     388
     389    bpdpw_pincode_product_price_meta_box_function($p);
    235390
    236391    wp_die();
     
    242397
    243398    global $wpdb;
    244     if(isset($_POST['variation_id']) && !empty($_POST['variation_id'])){
    245       $variation_id=$_POST['variation_id'];
    246     }else{
    247       $variation_id=0;
    248     }
    249399
    250400    $product_id = sanitize_text_field($_POST['product_id']);
     
    254404    $price = sanitize_text_field($_POST['price']);
    255405
    256     $exist = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $product_id . "' AND variation_id='".$variation_id."' AND pincode='" . $pincode . "'");
     406    $stock = sanitize_text_field($_POST['stock']);
     407
     408    $quantity = sanitize_text_field($_POST['quantity']);
     409
     410    $exist = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $product_id . "' AND pincode='" . $pincode . "'");
    257411
    258412    if (!empty($exist)) {
    259413
    260         $wpdb->query("UPDATE {$wpdb->prefix}pbdpw_product_price_pincode SET price='" . $price . "' WHERE product_id='" . $product_id . "' AND pincode='" . $pincode . "'  AND variation_id='".$variation_id."'");
     414        $wpdb->query("UPDATE {$wpdb->prefix}pbdpw_product_price_pincode SET price='" . $price . "',quantity='" . $quantity . "',stock='" . $stock . "' WHERE product_id='" . $product_id . "' AND pincode='" . $pincode . "'");
    261415
    262416    } else {
    263417
    264         $wpdb->query("INSERT INTO {$wpdb->prefix}pbdpw_product_price_pincode SET product_id='" . $product_id . "',  variation_id='".$variation_id."',pincode='" . $pincode . "',price='" . $price . "'");
     418        $wpdb->query("INSERT INTO {$wpdb->prefix}pbdpw_product_price_pincode SET product_id='" . $product_id . "',pincode='" . $pincode . "',price='" . $price . "',quantity='" . $quantity . "',stock='" . $stock . "'");
    265419
    266420    }
    267421
    268422    $p = get_post($product_id);
    269     if(!empty($variation_id)){
    270       bpdpw_pincode_variable_product_price_meta_box_function($p,$variation_id);
    271     }else{
    272      bpdpw_pincode_product_price_meta_box_function($p);
    273     }
     423
     424    bpdpw_pincode_product_price_meta_box_function($p);
    274425
    275426    wp_die();
     
    289440    $pincode_end = sanitize_text_field($_POST['pincode_end']);
    290441
    291     $price= sanitize_text_field($_POST['price']);
    292 
     442    $price = sanitize_text_field($_POST['price']);
     443
     444    $stock = sanitize_text_field($_POST['stock']);
     445
     446    $quantity = sanitize_text_field($_POST['quantity']);
    293447    if (!empty($pincode_start) && !empty($pincode_end) && ($pincode_start <= $pincode_end)) {
    294448
    295449        $pin_code_array = [];
    296450        $diff = $pincode_end - $pincode_start;
    297         $p_start=$pincode_start;
    298         for ($i = 0; $i <= $diff; $i++) {
    299             $pin_code_array[] = $p_start;
    300             $p_start++;
    301         }
    302      
    303     }else {
    304       $data['status']=false;
    305     }
    306    
    307     if (!empty($pin_code_array) && !empty($product_id) && !empty($pincode_start) && !empty($pincode_end) && !empty($price) ) {
    308 
    309         foreach ($pin_code_array as $pins) {
    310 
    311             $exist = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $product_id . "' AND pincode='" . $pins . "' ");
    312 
    313                 if (!empty($exist)) {
    314                     $data['status']=true;
    315                     $wpdb->query("UPDATE {$wpdb->prefix}pbdpw_product_price_pincode SET price='" . $price . "' WHERE product_id='" . $product_id . "' AND pincode='" . $pins  . "'");
    316 
    317                 } else {
    318                   $data['status']=true;
    319                     $wpdb->query("INSERT INTO {$wpdb->prefix}pbdpw_product_price_pincode SET product_id='" . $product_id . "',pincode='" . $pins  . "',price='" . $price . "'");
    320                 }
    321         }
    322     } else {
    323      
    324     }
    325 
    326       $p = get_post($product_id);
    327       if(!empty($variation_id)){
    328         bpdpw_pincode_variable_product_price_meta_box_function($p,$variation_id);
    329       }else{
    330         bpdpw_pincode_product_price_meta_box_function($p);
    331       }
    332    
    333       wp_die();
    334 
    335 }
    336 
    337 function bpdpw_variation_bulk_data_save_function()
    338 {
    339 
    340     global $wpdb;
    341     $data = [];
    342 
    343     $product_id = sanitize_text_field($_POST['product_id']);
    344 
    345     $variation_id = sanitize_text_field($_POST['post_variation_id']);
    346 
    347     $pincode_start = sanitize_text_field($_POST['pincode_start']);
    348 
    349     $pincode_end = sanitize_text_field($_POST['pincode_end']);
    350 
    351     $price = sanitize_text_field($_POST['price']);
    352 
    353     if (!empty($pincode_start) && !empty($pincode_end) && ($pincode_start <= $pincode_end)) {
    354 
    355         $pin_code_array = [];
    356         $diff = $pincode_end - $pincode_start;
    357        
    358451        for ($i = 0; $i <= $diff; $i++) {
    359452            $pin_code_array[] = $pincode_start;
     
    365458    }
    366459
    367     if (!empty($pin_code_array) && !empty($product_id) && !empty($pincode_start) && !empty($pincode_end) && !empty($price) ) {
     460    if (!empty($pin_code_array) && !empty($product_id) && !empty($pincode_start) && !empty($pincode_end) && !empty($price) && !empty($stock) && !empty(quantity)) {
    368461
    369462        foreach ($pin_code_array as $pins) {
    370463
    371             $exist = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $product_id . "' AND variation_id='".$variation_id."' AND pincode='" . $pins . "'");
     464            $exist = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $product_id . "' AND pincode='" . $pins . "'");
    372465
    373466                if (!empty($exist)) {
    374467                    $data['status']=true;
    375                     $wpdb->query("UPDATE {$wpdb->prefix}pbdpw_product_price_pincode SET price='" . $price . "' WHERE product_id='" . $product_id . "' AND pincode='" . $pins  . "' AND variation_id='".$variation_id."'");
     468                    $wpdb->query("UPDATE {$wpdb->prefix}pbdpw_product_price_pincode SET price='" . $price . "',quantity='" . $quantity . "',stock='" . $stock . "' WHERE product_id='" . $product_id . "' AND pincode='" . $pins  . "'");
    376469
    377470                } else {
    378471                  $data['status']=true;
    379                     $wpdb->query("INSERT INTO {$wpdb->prefix}pbdpw_product_price_pincode SET product_id='" . $product_id . "',variation_id='".$variation_id."',pincode='" . $pins  . "',price='" . $price . "'");
     472                    $wpdb->query("INSERT INTO {$wpdb->prefix}pbdpw_product_price_pincode SET product_id='" . $product_id . "',pincode='" . $pins  . "',price='" . $price . "',quantity='" . $quantity . "',stock='" . $stock . "'");
    380473                }
    381474        }
     
    385478
    386479      $p = get_post($product_id);
    387       bpdpw_pincode_variable_product_price_meta_box_function($p,$variation_id);
    388480   
     481      bpdpw_pincode_product_price_meta_box_function($p);
     482      // echo json_encode($data);
    389483      wp_die();
    390484
     
    461555                <form class="product_price_import" id="product_price_import" action="" method="post" name="product_price_import" >
    462556
    463                   <table class="table table-bordered table-responsive">
     557                  <table class="table table-bordered">
    464558
    465559                    <thead class="bg-primary">
     
    507601    <script >
    508602
     603       // jQuery(document).ready(function(){
     604
     605
    509606
    510607    jQuery("#product_price_import").submit(function(e) {
     
    597694            } else {
    598695
    599                 $result = $wpdb->query("INSERT into {$wpdb->prefix}pbdpw_product_price_pincode (product_id,variation_id,pincode,price  )
    600 
    601                    values ('" . $getData[0] . "','" . $getData[1] . "','" . $getData[2] . "','" . $getData[3] . "')");
     696                $result = $wpdb->query("INSERT into {$wpdb->prefix}pbdpw_product_price_pincode (product_id,pincode,price,quantity,stock  )
     697
     698                   values ('" . $getData[0] . "','" . $getData[1] . "','" . $getData[2] . "','" . $getData[3] . "','" . $getData[4] . "')");
    602699
    603700                $row++;
     
    652749
    653750    }
    654  
     751
    655752    $post_id = $product->get_id();
    656753
     
    659756    if (!empty($pincode)) {
    660757
    661       if($product->is_type('variable')){
    662      
    663         $nprice = $wpdb->get_row("SELECT MIN(price) as min_price , MAX(price) as max_price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $post_id . "' AND variation_id!='0'");
    664         if(!empty($nprice)){
    665           $min_price=wc_price($nprice->min_price);
    666           $max_price=wc_price($nprice->max_price);
    667        
     758        $nprice = $wpdb->get_var("SELECT price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $post_id . "'");
     759
     760        if (!empty($nprice)) {
     761
     762            $price = $nprice;
     763
    668764        }
    669       }else{
    670      
    671         $nprice = $wpdb->get_var("SELECT price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $post_id . "' AND variation_id='0'");
    672  
     765
     766    }
     767
     768    return $price;
     769
     770}function bpdpw_pincode_based_price_html($price, $product)
     771{
     772
     773    global $wpdb, $post, $blog_id;
     774
     775    if (isset($_SESSION['pincode_session_for_popup'])) {
     776
     777        $pincode = $_SESSION['pincode_session_for_popup'];
     778
     779    }
     780
     781    $post_id = $product->get_id();
     782
     783    $product = wc_get_product($post_id);
     784
     785    if (!empty($pincode)) {
     786
     787        $nprice = $wpdb->get_var("SELECT price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $post_id . "'");
     788
    673789        if (!empty($nprice)) {
    674  
    675             $price = $nprice;
    676  
     790
     791            $price = wc_price($nprice);
     792
    677793        }
    678 
    679       }
    680 
    681     }
    682 
    683     return $price;
    684 
    685 }function bpdpw_pincode_based_price_html($price, $product)
    686 {
    687 
    688     global $wpdb, $post, $blog_id;
    689 
    690     if (isset($_SESSION['pincode_session_for_popup'])) {
    691 
    692         $pincode = $_SESSION['pincode_session_for_popup'];
    693 
    694     }
    695 
    696     $post_id = $product->get_id();
    697 
    698     $product = wc_get_product($post_id);
    699 
    700     if (!empty($pincode)) {
    701 
    702       if($product->is_type('variable')){
    703        
    704         $nprice = $wpdb->get_row("SELECT min(price) as min_price , max(price) as max_price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $post_id . "' AND variation_id!='0'");
    705         if(!empty($nprice)){
    706           $min_price=wc_price($nprice->min_price);
    707           $max_price=wc_price($nprice->max_price);
    708           $price=$min_price.'-'.$max_price;
    709         }
    710       }else{
    711        
    712         $nprice = $wpdb->get_var("SELECT price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $post_id . "' AND variation_id='0'");
    713  
    714         if (!empty($nprice)) {
    715  
    716             $price = wc_price($nprice);
    717  
    718         }
    719 
    720       }
    721 
    722794
    723795    }
     
    770842  <!-- <div id="fade" class="black_overlay"></div> -->
    771843
     844    <script>
     845
     846      function bpdpw_save_pincode(){
     847
     848        var pincode=jQuery('#pincode').val();
     849
     850        if(pincode=='undefined' || pincode==''){
     851
     852          alert('Please fill your picode from where you want to purchage'); return false;
     853
     854        }
     855
     856       jQuery.ajax({
     857
     858          type: "POST",
     859
     860          url:woocommerce_params.ajax_url,
     861
     862          data:{
     863
     864          'action':'bpdpw_save_pincode',
     865
     866          'pincode':pincode,
     867
     868        },
     869
     870        success: function(data){
     871
     872         location.reload(true);
     873
     874        }
     875
     876      });
     877
     878      }
     879
     880      jQuery(document).ready(function(){
     881
     882        // jQuery('#light').css('display','block');
     883
     884        // jQuery('#fade').css('display','block');
     885
     886      });
     887
     888    </script>
     889
    772890    <?php
    773891
     
    796914  </div>
    797915
     916  <script>
     917
     918  function openNav() {
     919
     920    document.getElementById("mySidenav").style.width = "250px";
     921
     922  }
     923
     924
     925
     926  function closeNav() {
     927
     928    document.getElementById("mySidenav").style.width = "0";
     929
     930  }
     931
     932
     933
     934  function update_pincode(){
     935
     936    var pincode=jQuery('#update_pin').val();
     937
     938  jQuery.ajax({
     939
     940            type: "POST",
     941
     942            dataType: "json",
     943
     944            url:woocommerce_params.ajax_url,
     945
     946            data:{
     947
     948            'action':'bpdpw_update_pincode',
     949
     950            'pincode':pincode,
     951
     952          },
     953
     954          success: function(data){
     955
     956
     957
     958           location.reload(true);
     959
     960          }
     961
     962        });
     963
     964  }
     965
     966
     967
     968  </script>
    798969
    799970<?php
     
    803974}
    804975
    805 function bpdpw_variation_product_pincode_form($loop, $variation_data, $variation){
    806   global $wpdb,$post;
    807  
    808   if($post->post_status=='publish'){
    809     if(!empty($variation->ID)){
    810       bpdpw_pincode_variable_product_price_meta_box_function($post, $variation->ID);
    811       bpdpw_pincode_variation_product_price_bulk_meta_box_function($post, $variation);
    812     }
    813   }else{?>
    814 
    815     <div class="row ">
    816       <div class="col-md-12">
    817         <h2 class="bg-info"><?php _e('Pincode setting','bpdpw'); ?></h2>
    818         </div>
    819         <div class="col-md-12 m-3">
    820        <span class="alert alert-info"><?php   _e('Please publish this product first ...','bpdpw'); ?></span>
    821       </div>
    822       </div>
    823  <?php }
    824 }
    825 
    826 
    827 function bpdpw_pincode_variation_product_price_bulk_meta_box_function($post, $variation)
    828 {
    829 
    830     global $wpdb;?>
    831 
    832   <div class="col-md-12">
    833 
    834   <form method="POST" action="">
    835 
    836     <table  class="form-table table table-responsive">
    837 
    838     <thead>
    839 
    840       <tr class="tb-head ">
    841 
    842         <th class="tb-head" ><?php echo __('Pincode Range start', 'bpdpw'); ?></th>
    843 
    844         <th class="tb-head" ><?php echo __('Pincode Range end', 'bpdpw'); ?></th>
    845 
    846         <th class="tb-head"><?php echo __('Price', 'bpdpw'); ?></th>
    847 
    848         <th class="tb-head"><?php echo __('action', 'bpdpw'); ?></th>
    849 
    850       </tr>
    851 
    852       </thead>
    853 
    854       <tbody class="" id="">
    855        <tr>
    856          <input type="hidden" name="post_url" id="post_bulk_url<?php echo $variation->ID; ?>" value="<?php echo admin_url('admin-ajax.php'); ?>">
    857          <input type="hidden" name="variation_id" id="post_variation_id" value="<?php echo $variation->ID; ?>">
    858          <input type="hidden" name="product_id" id="post_ID<?php echo $variation->ID; ?>" value="<?php echo $variation->post_parent; ?>">
    859 
    860          <td class="tb-body"><input type="number" name="pin_start" id="pin_start<?php echo $variation->ID; ?>" value=""></td>
    861 
    862          <td class="tb-body"><input type="number" name="pin_end" id="pin_end<?php echo $variation->ID; ?>" value=""></td>
    863 
    864          <td class="tb-body"><input type="text" name="bulk_price" id="bulk_price<?php echo $variation->ID; ?>" value=""></td>
    865 
    866           <td><button class="text-center button " type="button" onclick="bpdpw_variation_save_bulk(<?php echo  $variation->ID; ?>)" ><?php _e('Save','bpdpw');?></button></td>
    867 
    868        </tr>
    869        <tr> <td class="error_msg<?php echo $variation->ID; ?>" colspan="4"></td></tr>
    870       </tbody>
    871     </table>
    872  
    873 </div>
    874 
    875 <?php }
    876 
    877 
    878 function bpdpw_pincode_variable_product_price_meta_box_function($post,$variation)
    879 {
    880 
    881     global $wpdb;
    882 
    883     $num_row = 0;
    884 
    885     $results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $post->ID . "' AND variation_id='".$variation."'");
    886 
    887     ?>
    888 
    889     <div>
    890 
    891    <div class="div_pincode_<?php echo $variation; ?>" id="div_pincode_<?php echo $variation; ?>">
    892 
    893      <form method="POST" action="">
    894 
    895       <table  class="form-table table table-responsive">
    896 
    897      <thead>
    898 
    899       <tr class="tb-head ">
    900 
    901         <th class="tb-head"><?php echo __('Pincode', 'bpdpw'); ?></th>
    902 
    903         <th class="tb-head"><?php echo __('Price', 'bpdpw'); ?></th>
    904 
    905         <th class="tb-head"><?php echo __('Action', 'bpdpw'); ?></th>
    906 
    907       </tr>
    908 
    909         </thead>
    910 
    911         <tbody class="append_data<?php echo $variation; ?>" id="append_data<?php echo $variation; ?>">
    912 
    913         <input type="hidden" name="post_url" id="post_url<?php echo $variation; ?>" value="<?php echo admin_url('admin-ajax.php'); ?>">
    914         <input type="hidden" name="post_ID" id="post_ID<?php echo $variation; ?>" value="<?php echo  $post->ID; ?>">
    915 
    916         <?php foreach ($results as $result) {?>
    917 
    918           <tr id="row_<?php echo $num_row.$result->variation_id; ?>"><td class="tb-body"><input class="short" type='text' value="<?php echo $result->pincode; ?>" name='pincode'  id="pincode_<?php echo $num_row.$result->variation_id; ?>"></td><td class="tb-body"><input type='text' class="short" value="<?php echo $result->price; ?>" name='price'  id="price_<?php echo $num_row.$result->variation_id; ?>"></td><td class="row tb-body" style="display: flex;"><button class="button" type='button'  onclick='bpdpw_variation_save(<?php echo $num_row; ?>,<?php echo $result->variation_id; ?>); return true;' style="float: left"><?php echo __('Save', 'bpdpw'); ?></button><button class="button" type='button'  onclick='bpdpw_variation_delete(<?php echo $result->id; ?>,<?php echo $result->product_id; ?>,<?php echo $result->variation_id; ?>); return true;' ><?php echo __('Delete', 'bpdpw'); ?></button></td></tr>
    919 
    920         <?php
    921 
    922         $num_row++;
    923 
    924     }?>
    925 
    926 
    927 
    928         </tbody>
    929 
    930       <tfoot><td colspan="2"></td><td><button class="button" id="add_row" type="button" data-num-row="<?php echo $num_row; ?>" onclick="add_variation_pin(jQuery(this).attr('data-num-row'),<?php echo $variation;?>)"><?php echo __('Add', 'bpdpw'); ?></button></td>
    931 
    932   </tfoot>
    933 
    934   </table>
    935 
    936   </form>
    937 
    938 </div>
    939 
    940 </div>
    941 
    942 
    943 
    944 <script>
    945 
    946   var num_row='<?php echo $num_row; ?>';
    947 
    948   function add_variation_pin(num_row,v_id){
    949 
    950     jQuery("<tr id='row_"+num_row+"'><td><input type='text' class='short' name='pincode'  id='pincode_"+num_row+v_id+"'></td><td><input type='text' class='short' name='price'  id='price_"+num_row+v_id+"'></td><td><button type='button'  onclick='bpdpw_variation_save("+num_row+","+v_id+"); return true;''><?php echo __('Save', 'bpdpw'); ?></button></td></tr>").fadeIn().appendTo(".append_data"+v_id);
    951 
    952     num_row++;
    953 
    954     jQuery('#add_row').attr('data-num-row',num_row);
    955 
    956   }
    957 </script>
    958 
    959   <?php
    960 
    961 }
    962 
    963 
    964  
    965 
    966 
    967 
    968  function custom_price( $price, $product ) {
    969 
    970   global $wpdb;
    971   if(isset($_SESSION['pincode_session_for_popup']) && !empty($_SESSION['pincode_session_for_popup'])){
    972     $pincode=$_SESSION['pincode_session_for_popup'];
    973    
    974     $exist=$wpdb->get_var("SELECT max(price) as price from {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='".$product->parent_id."' AND variation_id!='0' AND pincode='".$pincode."'");
    975     if(!empty($exist)){
    976       $price=$exist;
    977      }
    978 }
    979 
    980   return (float) $price ;
    981 }
    982 
    983  function custom_variable_price( $price, $variation, $product ) {
    984   return 300;
    985  
    986   if(isset($_SESSION['pincode_session_for_popup']) && !empty($_SESSION['pincode_session_for_popup'])){
    987     $pincode=$_SESSION['pincode_session_for_popup'];
    988     $exist=$wpdb->get_var("SELECT max(price) as price from {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='".$product->parent_id."' AND variation_id='".$variation->ID."' AND pincode='".$pincode."'");
    989     if(!empty($exist)){
    990       $price=$exist;
    991      }
    992   }
    993   return (float) $price * get_price_multiplier();
    994 }
    995 
    996  function add_price_multiplier_to_variation_prices_hash( $price_hash, $product, $for_display ) {
    997   $price_hash[] = get_price_multiplier();
    998   return $price_hash;
    999 }
    1000 
    1001 function filter_available_variation_data_function($data){
    1002   global $wpdb;
    1003   $exist='';
    1004  
    1005   if(isset($_SESSION['pincode_session_for_popup']) && !empty($_SESSION['pincode_session_for_popup'])){
    1006     $pincode=$_SESSION['pincode_session_for_popup'];
    1007     $product_id = wp_get_post_parent_id($data['variation_id']);
    1008    
    1009     $exist=$wpdb->get_var("SELECT MAX(price) as price from {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='".$product_id."' AND variation_id='".$data['variation_id']."' AND pincode='".$pincode."'");
    1010     if(!empty($exist)){
    1011       $data['price_html']=$exist;
    1012      }
    1013   }
    1014   return $data;
    1015 }
    1016 
    1017 
    1018 
    1019 function bpdpw_change_minicart_item_price( $price, $cart_item, $cart_item_key){
    1020   global $wpdb;
    1021   if ( ! is_cart() ) {
    1022     if($cart_item){
    1023      
    1024         $product_id = $cart_item['product_id'];
    1025 
    1026         if(!empty($cart_item['variation_id'])){
    1027 
    1028           $variation_id=$cart_item['variation_id'];
    1029 
    1030         }else{
    1031 
    1032           $variation_id=0;
    1033 
    1034         }
    1035 
    1036         $pincode = $_SESSION['pincode_session_for_popup'];
    1037        
    1038         if(empty($cart_item['data']->get_sale_price())){
    1039 
    1040           $price = $cart_item['data']->get_regular_price();
    1041 
    1042         }else{
    1043 
    1044           $price = $cart_item['data']->get_sale_price();
    1045 
    1046         }
    1047 
    1048         if (!empty($pincode)) {
    1049            
    1050             $newprice = $wpdb->get_var("SELECT price FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE pincode='" . $pincode . "' AND product_id='" . $product_id . "' AND variation_id='".$variation_id."'");
    1051 
    1052             if (!empty($newprice)) {
    1053 
    1054                 $price = wc_price($newprice);
    1055 
    1056             }
    1057 
    1058         }
    1059       }
    1060   }
    1061 
    1062 return $price;
    1063 }
    1064 
    1065976?>
  • pincode-based-product-price-woocommerce/trunk/includes/class-pbdpw-hooks.php

    r2759776 r2759778  
    1111add_action('wp_ajax_nopriv_bpdpw_data_save','bpdpw_save_function');
    1212
    13 
    14 add_action('wp_ajax_bpdpw_variation_bulk_data_save','bpdpw_variation_bulk_data_save_function');
    1513
    1614add_action('wp_ajax_bpdpw_bulk_data_save','bpdpw_bulk_save_function');
     
    6967add_action('wp_ajax_nopriv_bpdpw_check_pincode_session','bpdpw_check_pincode_session_function');
    7068
    71 add_action('woocommerce_product_after_variable_attributes','bpdpw_variation_product_pincode_form',3,100);
    72 
    73 
    74 // Variations
    75 // add_filter('woocommerce_product_variation_get_regular_price',  'custom_price' , 100, 2 );
    76 // add_filter('woocommerce_product_variation_get_price',  'custom_price' , 99, 2 );
    77 
    78 
    79 add_filter('woocommerce_available_variation',  'filter_available_variation_data_function' , 999, 1 );
    80 
    81 add_filter( 'woocommerce_cart_item_price', 'bpdpw_change_minicart_item_price', 10, 3 );
    82 
    8369?>
  • pincode-based-product-price-woocommerce/trunk/includes/class-pbdpw-product-admin.php

    r2759776 r2759778  
    163163
    164164    {  if($post->post_status=='publish'){
    165         $product=get_product($post->ID);
    166         if(!$product->is_type('variable')){
     165
    167166            do_action('bpdpw_pincode_product_price_meta_box',$post);
    168         }else{
    169             echo 'This is a variable product, To set pincode go to variation save varations and then on variation form you can edit pincodes';
     167
     168        } else{
     169
     170            echo 'Current Product is not Published. Please publish Product to use this feature';
     171
    170172        }
     173
     174    }
     175
     176
     177
     178    public function pincode_product_price_bulk_metta_box($post)
     179
     180    {  if($post->post_status=='publish'){
     181
     182            do_action('bpdpw_pincode_product_price_bulk_meta_box',$post);
     183
     184        } else{
     185
     186            echo 'Current Product is not Published. Please publish Product to use this feature';
     187
     188        }
     189
     190    }
     191
     192
     193
     194    public function save_meta_boxes(){
     195
     196
     197
     198    }
     199
    171200   
    172201
    173         } else{
    174 
    175             echo 'Current Product is not Published. Please publish Product to use this feature';
    176 
    177         }
    178 
    179     }
    180 
    181 
    182 
    183     public function pincode_product_price_bulk_metta_box($post)
    184 
    185     {  if($post->post_status=='publish'){
    186                 $product=get_product($post->ID);
    187                 if(!$product->is_type('variable')){
    188                  do_action('bpdpw_pincode_product_price_bulk_meta_box',$post);
    189                 }else{
    190                     echo 'This is a variable product, To set pincode go to variation save varations and then on variation form you can edit pincodes';
    191                 }
    192            
    193 
    194         } else{
    195 
    196             echo 'Current Product is not Published. Please publish Product to use this feature';
    197 
    198         }
    199 
    200     }
    201 
    202 
    203 
    204     public function save_meta_boxes(){
    205 
    206 
    207 
    208     }
    209 
    210    
    211 
    212202}
    213203
  • pincode-based-product-price-woocommerce/trunk/includes/class-pbdpw.php

    r2759776 r2759778  
    169169        register_deactivation_hook( PBDPW_PLUGIN_FILE, array( 'PBDPW_Install', 'deactivate' ) );
    170170
    171         add_action('init', array($this,'pbdpw_check_table_and_field_create'));
     171
    172172
    173173        register_uninstall_hook( PBDPW_PLUGIN_FILE, 'uninstall' );
     
    198198
    199199            // add_action( 'admin_enqueue_scripts', array($this,'custom_pbdpw_admin_style' ));
    200             wp_enqueue_script('PBDPW_main', PBDPW()->plugin_url() .'/assets/js/main.js',array('jquery'),'',true );
    201         }
    202         // add_action('wp_footer',array($this,'pbdpw_enqueue_files'));
     200
     201        }
     202
    203203        wp_enqueue_script( 'PBDPW_swal_js', PBDPW()->plugin_url() .'/assets/js/sweetalert2.all.min.js', array('jquery'), '' ,true);
     204        // wp_enqueue_style( 'PBDPW_swal_css', 'https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css', array(''), '' );
    204205        wp_enqueue_style( 'PBDPW_styles', PBDPW()->plugin_url() . '/assets/css/front.css', array(), '' );
    205 
    206         add_action('admin_print_styles-post.php',  array($this,'pbdpw_custom_js_css'));
    207         add_action('admin_print_styles-post-new.php',  array($this,'pbdpw_custom_js_css'));
    208        
    209     }
    210     function pbdpw_custom_js_css(){
    211         // wp_enqueue_script('PBDPW_main', PBDPW()->plugin_url() .'/assets/js/main.js',array('jquery'),'',true );
    212     }
    213 
    214     function custom_pbdpw_admin_style($hook){
    215         // die($hook);
    216         if($hook=='post.php'){
    217             wp_enqueue_style( 'PBDPW_bootstrap_styles', 'https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css', array(), '' );
    218             // wp_enqueue_script('PBDPW_main', PBDPW()->plugin_url() .'/assets/js/main.js',array('jquery'),'',true );
    219         }
    220            
    221     }
    222 
    223     function pbdpw_check_table_and_field_create(){
    224         global $wpdb;
    225        
    226         $table_exist=$wpdb->get_var("SHOW TABLES LIKE '%{$wpdb->prefix}pbdpw_product_price_pincode%'");
    227         if(!empty($table_exist)){
    228        
    229             $wpdb->get_var("ALTER TABLE {$wpdb->prefix}pbdpw_product_price_pincode ADD COLUMN IF NOT EXISTS variation_id INT(11) NOT NULL DEFAULT '0'");
    230 
    231         }else{
    232 
    233         $collate = '';
    234 
    235         if ( $wpdb->has_cap( 'collation' ) ) {
    236 
    237             $collate = $wpdb->get_charset_collate();
    238 
    239         }
    240 
    241         $table =  $wpdb->get_query("CREATE TABLE IF NOT EXISTS {$wpdb->prefix}pbdpw_product_price_pincode (
    242 
    243             id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    244 
    245             product_id BIGINT(20) NOT NULL,
    246 
    247             pincode VARCHAR(6) NOT NULL ,
    248 
    249             price VARCHAR(128) NOT NULL ,
    250 
    251             quantity INT(15) NOT NULL ,
    252 
    253             stock INT(1) NOT NULL
    254 
    255             ) $collate;");
    256         }
    257     }
    258 
    259    
     206    }
     207
    260208    function pbdpw_sweetalert_popup_main(){
    261        
    262209        $ajaxurl=admin_url('admin-ajax.php');
    263210        echo '<script>
    264211        var ajaxurl="'.$ajaxurl.'";
    265        
    266212        window.addEventListener("load", function () {  jQuery.ajax({type: "POST",url: ajaxurl,data: {"action":"bpdpw_check_pincode_session",},dataType: "json",success: function (data) { console.log(data.status);if (data.status == false) {  Swal.fire({
    267213            title: "Enter you pincode",
     
    324270        add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
    325271
     272       
     273
     274
     275
    326276    }
    327277
     
    331281
    332282    {
     283
    333284        global $menu;
    334285
     286
     287
    335288        $icon=PBDPW()->plugin_url() . '/assets/images/zip-code.png';
    336289
    337         add_menu_page(__( 'Pincode price', 'PBDPW' ), __( 'Pincode price Pro', 'PBDPW' ),'manage_options','PBDPW-user-report',array($this, 'settings_page_init'),$icon,100);
     290        add_menu_page(__( 'Pincode price', 'PBDPW' ), __( 'Pincode price', 'PBDPW' ),'manage_options','PBDPW-user-report',array($this, 'settings_page_init'),$icon,100);
    338291
    339292        }
Note: See TracChangeset for help on using the changeset viewer.