Changeset 2759778
- Timestamp:
- 07/21/2022 12:08:16 PM (3 years ago)
- Location:
- pincode-based-product-price-woocommerce/trunk/includes
- Files:
-
- 4 edited
-
class-pbdpw-hooks-function.php (modified) (26 diffs)
-
class-pbdpw-hooks.php (modified) (2 diffs)
-
class-pbdpw-product-admin.php (modified) (1 diff)
-
class-pbdpw.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pincode-based-product-price-woocommerce/trunk/includes/class-pbdpw-hooks-function.php
r2759776 r2759778 16 16 $product_id = $value['product_id']; 17 17 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 } 25 31 26 32 } 27 33 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 52 34 $value['data']->set_price($newprice); 53 35 … … 61 43 { 62 44 63 global $wpdb; 64 $product = get_product( $post->ID ); 65 ?> 45 global $wpdb;?> 66 46 67 47 <div class="col-md-12"> … … 80 60 81 61 <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> 82 66 83 67 <th class="tb-head"><?php echo __('action', 'bpdpw'); ?></th> … … 91 75 <input type="hidden" name="post_url" id="post_bulk_url" value="<?php echo admin_url('admin-ajax.php'); ?>"> 92 76 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> 96 80 97 81 <td class="tb-body"><input type="text" name="bulk_price" id="bulk_price" value=""></td> 98 82 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> 100 92 101 93 </tr> 102 103 94 <tr> <td class="error_msg" colspan="4"></td></tr> 104 95 </tbody> 105 96 </table> 106 107 97 <script> 108 98 109 99 100 function bpdpw_save_bulk(){ 101 102 var bulk_pincode_start=jQuery('#pin_start').val(); 103 104 var 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 110 var bulk_stock=jQuery('#bulk_stock').val(); 111 112 var link = jQuery('#post_bulk_url').val(); 113 114 var product_id = jQuery('#post_ID').val(); 115 116 console.log(parseInt(bulk_pincode_start)>=parseInt(bulk_pincode_end)); 117 if(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 } 127 if(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 138 jQuery.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 162 success: 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 } 110 181 111 182 </script> … … 114 185 <?php } 115 186 116 117 118 119 120 121 122 123 187 function bpdpw_pincode_product_price_meta_box_function($post) 124 188 { 125 $product = get_product( $post->ID ); 126 189 127 190 global $wpdb; 128 191 129 192 $num_row = 0; 130 193 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 . "'"); 132 195 133 196 ?> … … 139 202 <form method="POST" action=""> 140 203 141 <table class="form-table table table-responsive">204 <table class="form-table"> 142 205 143 206 <thead> … … 149 212 <th class="tb-head"><?php echo __('Price', 'bpdpw'); ?></th> 150 213 214 <th class="tb-head"><?php echo __('Quantity', 'bpdpw'); ?></th> 215 216 <th class="tb-head"><?php echo __('Stock', 'bpdpw'); ?></th> 217 151 218 <th class="tb-head"><?php echo __('Action', 'bpdpw'); ?></th> 152 219 … … 161 228 <?php foreach ($results as $result) {?> 162 229 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> 164 231 165 232 <?php … … 173 240 </tbody> 174 241 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> 176 243 177 244 </tfoot> … … 193 260 function add(num_row){ 194 261 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"); 196 265 197 266 num_row++; … … 203 272 204 273 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 329 function 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 205 370 </script> 206 371 … … 214 379 global $wpdb; 215 380 216 if(isset($_POST['variation_id']) && !empty($_POST['variation_id'])){217 $variation_id=$_POST['variation_id'];218 }else{219 $variation_id=0;220 }221 222 381 $id = sanitize_text_field($_POST['id']); 223 382 … … 225 384 226 385 $wpdb->query("DELETE FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE id='" . $id . "'"); 227 386 228 387 $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); 235 390 236 391 wp_die(); … … 242 397 243 398 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 }249 399 250 400 $product_id = sanitize_text_field($_POST['product_id']); … … 254 404 $price = sanitize_text_field($_POST['price']); 255 405 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 . "'"); 257 411 258 412 if (!empty($exist)) { 259 413 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 . "'"); 261 415 262 416 } else { 263 417 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 . "'"); 265 419 266 420 } 267 421 268 422 $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); 274 425 275 426 wp_die(); … … 289 440 $pincode_end = sanitize_text_field($_POST['pincode_end']); 290 441 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']); 293 447 if (!empty($pincode_start) && !empty($pincode_end) && ($pincode_start <= $pincode_end)) { 294 448 295 449 $pin_code_array = []; 296 450 $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 358 451 for ($i = 0; $i <= $diff; $i++) { 359 452 $pin_code_array[] = $pincode_start; … … 365 458 } 366 459 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)) { 368 461 369 462 foreach ($pin_code_array as $pins) { 370 463 371 $exist = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $product_id . "' AND variation_id='".$variation_id."' ANDpincode='" . $pins . "'");464 $exist = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}pbdpw_product_price_pincode WHERE product_id='" . $product_id . "' AND pincode='" . $pins . "'"); 372 465 373 466 if (!empty($exist)) { 374 467 $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 . "'"); 376 469 377 470 } else { 378 471 $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 . "'"); 380 473 } 381 474 } … … 385 478 386 479 $p = get_post($product_id); 387 bpdpw_pincode_variable_product_price_meta_box_function($p,$variation_id);388 480 481 bpdpw_pincode_product_price_meta_box_function($p); 482 // echo json_encode($data); 389 483 wp_die(); 390 484 … … 461 555 <form class="product_price_import" id="product_price_import" action="" method="post" name="product_price_import" > 462 556 463 <table class="table table-bordered table-responsive">557 <table class="table table-bordered"> 464 558 465 559 <thead class="bg-primary"> … … 507 601 <script > 508 602 603 // jQuery(document).ready(function(){ 604 605 509 606 510 607 jQuery("#product_price_import").submit(function(e) { … … 597 694 } else { 598 695 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] . "')"); 602 699 603 700 $row++; … … 652 749 653 750 } 654 751 655 752 $post_id = $product->get_id(); 656 753 … … 659 756 if (!empty($pincode)) { 660 757 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 668 764 } 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 673 789 if (!empty($nprice)) { 674 675 $price = $nprice;676 790 791 $price = wc_price($nprice); 792 677 793 } 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 722 794 723 795 } … … 770 842 <!-- <div id="fade" class="black_overlay"></div> --> 771 843 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 772 890 <?php 773 891 … … 796 914 </div> 797 915 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> 798 969 799 970 <?php … … 803 974 } 804 975 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 <?php921 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 <?php960 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 1065 976 ?> -
pincode-based-product-price-woocommerce/trunk/includes/class-pbdpw-hooks.php
r2759776 r2759778 11 11 add_action('wp_ajax_nopriv_bpdpw_data_save','bpdpw_save_function'); 12 12 13 14 add_action('wp_ajax_bpdpw_variation_bulk_data_save','bpdpw_variation_bulk_data_save_function');15 13 16 14 add_action('wp_ajax_bpdpw_bulk_data_save','bpdpw_bulk_save_function'); … … 69 67 add_action('wp_ajax_nopriv_bpdpw_check_pincode_session','bpdpw_check_pincode_session_function'); 70 68 71 add_action('woocommerce_product_after_variable_attributes','bpdpw_variation_product_pincode_form',3,100);72 73 74 // Variations75 // 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 83 69 ?> -
pincode-based-product-price-woocommerce/trunk/includes/class-pbdpw-product-admin.php
r2759776 r2759778 163 163 164 164 { if($post->post_status=='publish'){ 165 $product=get_product($post->ID); 166 if(!$product->is_type('variable')){ 165 167 166 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 170 172 } 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 171 200 172 201 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 212 202 } 213 203 -
pincode-based-product-price-woocommerce/trunk/includes/class-pbdpw.php
r2759776 r2759778 169 169 register_deactivation_hook( PBDPW_PLUGIN_FILE, array( 'PBDPW_Install', 'deactivate' ) ); 170 170 171 add_action('init', array($this,'pbdpw_check_table_and_field_create')); 171 172 172 173 173 register_uninstall_hook( PBDPW_PLUGIN_FILE, 'uninstall' ); … … 198 198 199 199 // 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 203 203 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(''), '' ); 204 205 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 260 208 function pbdpw_sweetalert_popup_main(){ 261 262 209 $ajaxurl=admin_url('admin-ajax.php'); 263 210 echo '<script> 264 211 var ajaxurl="'.$ajaxurl.'"; 265 266 212 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({ 267 213 title: "Enter you pincode", … … 324 270 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 ); 325 271 272 273 274 275 326 276 } 327 277 … … 331 281 332 282 { 283 333 284 global $menu; 334 285 286 287 335 288 $icon=PBDPW()->plugin_url() . '/assets/images/zip-code.png'; 336 289 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); 338 291 339 292 }
Note: See TracChangeset
for help on using the changeset viewer.