Changeset 913504
- Timestamp:
- 05/13/2014 07:59:52 PM (12 years ago)
- Location:
- postcode-shipping/trunk
- Files:
-
- 3 edited
-
postcode_shipping.php (modified) (18 diffs)
-
readme.txt (modified) (3 diffs)
-
screenshot-1.png (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
postcode-shipping/trunk/postcode_shipping.php
r839225 r913504 1 1 <?php 2 2 3 /** 4 5 * Plugin Name: Postcode Shipping 6 7 * Plugin URI: http://www.dimensionit.com 8 9 * Description: This plugin allows you to set a flat shipping rate per country or state or postcode per Quantity/Order on WooCommerce. 10 11 * Version: 2.0 12 13 * Author: Rizwan Ahammad 14 15 * Author URI: http://www.dimensionit.com 16 17 * Text Domain: woocommerce_flatrate_perpostcode 18 19 * Domain Path: /lang 20 21 **/ 22 23 24 25 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 26 27 28 3 29 /** 4 30 5 * Plugin Name: Postcode Shipping6 7 * Plugin URI: http://www.dimensionit.com8 9 * Description: This plugin allows you to set a flat shipping rate per country or state or postcode on WooCommerce.10 11 * Version: 1.012 13 * Author: Rizwan Ahammad14 15 * Author URI: http://www.dimensionit.com16 17 * Text Domain: woocommerce_flatrate_perpostcode18 19 * Domain Path: /lang20 21 **/22 23 24 25 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly26 27 28 29 /**30 31 31 * Check if WooCommerce is active 32 32 … … 67 67 $this->method_title = __('Postcode Shipping', $this->id); 68 68 69 $this->method_description = __('Postcode shipping rates let you define a standard rate per order.<br/><br/> If you set a rate for the client\'s country it will be Apply.</br> if you set a rate for client\'s state it will be Apply. Otherwise,<br/>if you set a rate for client\'s Zip/postcode it will be Apply.</br> If none of the rates are set, the "Rest of the World" rate will be Apply.', $this->id);69 $this->method_description = __('Postcode shipping rates let you define a standard rate per order.<br/><br/>if you set a rate for client\'s Zip/postcode it will be Apply.</br> if you set a rate for client\'s state it will be Apply.<br/>If you set a rate for the client\'s country it will be Apply. Otherwise,</br> If none of the rates are set, the "Rest of the World" rate will be Apply.<br/><br/> Now you can add Shipping Rates Based on Quantity <br/> You can add Shipping Rates between 2 postcode zones', $this->id); 70 70 71 71 $this->wc_shipping_init(); … … 100 100 101 101 102 $this->title = $this->settings['title'];103 104 $this->enabled = $this->settings['enabled'];102 $this->title = $this->settings['title']; 103 104 $this->enabled = $this->settings['enabled']; 105 105 106 106 … … 134 134 135 135 ), 136 137 'tax_status' => array( 138 139 'title' => __('Tax Status', 'woocommerce'), 140 141 'type' => 'select', 142 143 'description' => '', 144 145 'default' => 'taxable', 146 147 'options' => array( 148 149 'taxable' => __('Taxable', 'woocommerce'), 150 151 'none' => __('None', 'woocommerce'), 152 153 ), 154 155 ), 136 156 137 157 'title' => array( … … 146 166 147 167 ), 148 149 'tax_status' => array( 150 151 'title' => __('Tax Status', 'woocommerce'), 152 153 'type' => 'select', 154 155 'description' => '', 156 157 'default' => 'taxable', 158 159 'options' => array( 160 161 'taxable' => __('Taxable', 'woocommerce'), 162 163 'none' => __('None', 'woocommerce'), 164 165 ), 166 167 ), 168 168 169 169 170 'fee_world' => array( … … 180 181 181 182 ), 183 184 'country_title' => array( 185 186 'title' => __('Country Method Title', 'woocommerce'), 187 188 'type' => 'text', 189 190 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 191 192 'default' => __('Postcode Shipping(country)', $this->id), 193 194 ), 182 195 183 196 'per_country_count' => array( … … 192 205 193 206 ), 207 208 'state_title' => array( 209 210 'title' => __('State Method Title', 'woocommerce'), 211 212 'type' => 'text', 213 214 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 215 216 'default' => __('Postcode Shipping(state)', $this->id), 217 218 ), 194 219 195 220 'per_state_count' => array( … … 204 229 205 230 ), 231 232 'postcode_title' => array( 233 234 'title' => __('Postcode Method Title', 'woocommerce'), 235 236 'type' => 'text', 237 238 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 239 240 'default' => __('Postcode Shipping(postcode)', $this->id), 241 242 ), 206 243 207 244 'per_postcode_count' => array( … … 271 308 'type' => 'text', 272 309 273 'description' => __(' The shipping fee for the countries specified above.', $this->id),310 'description' => __('Set your quantity based shipping fee with comma separated values for the countries specified above. Example:Quantity|Price,Quantity|Price. Example: 1|100,2|500.00 OR you can enter single price for all quantities Example: 100.00', $this->id), 274 311 275 312 'default' => '', 276 313 277 'placeholder' => ' 0.0',314 'placeholder' => '1|10.00', 278 315 279 316 ); … … 344 381 'type' => 'text', 345 382 346 'description' => __(' The shipping fee for the state specified above.', $this->id),383 'description' => __('Set your quantity based shipping fee with comma separated values for the state specified above. Example:Quantity|Price,Quantity|Price. Example: 1|100,2|500.00 OR you can enter single price for all quantities Example: 100.00', $this->id), 347 384 348 385 'default' => '', 349 386 350 'placeholder' => ' 0.0',387 'placeholder' => '1|10.00', 351 388 352 389 ); … … 364 401 /* per PostNumber form fields*/ 365 402 366 367 368 403 function init_shipping_fields_per_postcode() { 369 404 370 371 372 405 global $woocommerce; 373 374 375 406 376 407 $this->form_fields['per_postcode']=array( 377 408 … … 385 416 386 417 387 388 418 $count=$this->settings['per_postcode_count']; 389 419 390 420 391 392 421 for($counter = 1; $count >= $counter; $counter++) { 393 422 … … 398 427 'type' => 'textarea', 399 428 400 'description' => __('Choose one or more Postcodes for this rule. Separate codes with a comma ', $this->id),429 'description' => __('Choose one or more Postcodes for this rule. Separate codes with a comma and you can add postcode between 2 zones Example: 12345-12350,123456', $this->id), 401 430 402 431 'default' => '', 403 432 404 'placeholder' => '12345 ,23456 ect',433 'placeholder' => '12345-12350,123456 ect', 405 434 406 435 ); … … 412 441 'type' => 'text', 413 442 414 'description' => __(' The shipping fee for all the postcodes specified above.', $this->id),443 'description' => __('Set your quantity based shipping fee with comma separated values for all postcodes specified above. Example:Quantity|Price,Quantity|Price. Example: 1|100,2|500.00 OR you can enter single price for all quantities Example: 100.00', $this->id), 415 444 416 445 'default' => '', 417 446 418 'placeholder' => ' 0.0',447 'placeholder' => '1|10.00', 419 448 420 449 ); … … 425 454 426 455 427 428 456 } 429 430 431 457 458 /*** 459 * Find Postcode Function 460 * Usage: getPostcode(User_Enterd_Postcode, '1000-2000') 461 */ 462 public function getPostcode($Usercode, $mpostcode){ 463 464 $mpostcode = explode("-",$mpostcode); 465 466 $fCode= $mpostcode[0]; 467 $lCode = $mpostcode[1]; 468 for($fc=$fCode; $fc<=$lCode; $fc++){ 469 if($Usercode == $fc){ 470 $postCode=$fc; 471 break; 472 } 473 else{ 474 $postCode=''; 475 } 476 } 477 478 return $postCode; 479 } 480 481 /*** 482 * Method Title: calPriceByQuantity 483 * Description : Calulate shipping Price By Quantity 484 * Syntax : calPriceByQuantity('cart_qty','qty|price,qty|price,qty|price') 485 * Usage: calPriceByQuantity('2', '1|100,2|200,3|300') 486 * Result: 200 487 */ 488 function calPriceByQuantity($Qty,$Price){ 489 490 $shipPrice =''; 491 492 //Explode Price Classes 493 $priceValue = explode(",",$Price); 494 495 //Count of Price Classes 496 $countPriceValue = count($priceValue); 497 498 //Get Last Price Class 499 $lastPriceClass = $priceValue[$countPriceValue-1]; 500 501 for($v=0; $v<$countPriceValue; $v++){ 502 503 $priceWithQty = $priceValue[$v]; 504 505 $finalPrice=$this->getQtyPrice($Qty, $priceWithQty); 506 507 if($finalPrice != ''){ 508 509 $shipPrice =$finalPrice; 510 511 break; 512 } 513 514 } 515 516 //If Quantity exceeded. Last class price Will Apply 517 if($lastPriceClass !='' && $shipPrice==''){ 518 519 //Explode Last Price Class 520 $otherPrice = explode("|",$lastPriceClass); 521 522 $shipPrice=$otherPrice[1]; 523 524 } 525 526 return $shipPrice; 527 } 528 529 /*** 530 * Method Title: getQtyPrice 531 * Description : Returns shipping Price By Quantity. Here You calciulate price only for single quantity. 532 * Syntax : getQtyPrice('cart_qty','qty|price') 533 * Usage: getQtyPrice('1', '1|100') 534 * Result: 100 535 */ 536 function getQtyPrice($Qty, $priceWithQty){ 537 538 $qtyPrice = explode("|",$priceWithQty); 539 540 $qQuantity = $qtyPrice[0]; 541 $qPrice= ''; 542 543 if($Qty >0 && $Qty <= $qQuantity){ 544 545 //Return Price 546 $qPrice= $qtyPrice[1]; 547 548 } 549 550 return $qPrice; 551 552 } 553 554 555 432 556 /* Calculate the rate */ 433 557 … … 439 563 440 564 $label=''; 441 442 if(trim($package['destination']['country'])!='') { 443 565 566 /** Method Title For Wordwide Shipping*/ 567 $commonLabel=$this->settings['title']; 568 569 570 if(trim($package['destination']['postcode'])!='' || trim($package['destination']['state'])!='' || trim($package['destination']['country'])!='' ) { 571 572 //Assign Default Flate Rate as False 444 573 $final_rate=false; 445 446 //Country 447 448 $count=$this->settings['per_country_count']; 449 450 for($i=1; $i<=$count; $i++){ 451 452 if (is_array($this->settings['per_country_'.$i.'_country'])) { 453 454 if (in_array(trim($package['destination']['country']), $this->settings['per_country_'.$i.'_country'])) { 455 456 $final_rate=floatval($this->settings['per_country_'.$i.'_fee']); 457 458 $label=$woocommerce->countries->countries[trim($package['destination']['country'])]; 459 460 break; 461 462 } 463 464 } 465 466 } 467 468 469 //State 470 471 if ($final_rate===false) { 472 473 $count=$this->settings['per_state_count']; 474 475 for($i=1; $i<=$count; $i++){ 476 477 if (is_array($this->settings['per_state_'.$i.'_state'])) { 478 479 if (in_array(trim($package['destination']['state']), $this->settings['per_state_'.$i.'_state'])) { 480 481 $final_rate=floatval($this->settings['per_state_'.$i.'_fee']); 482 483 $label=$woocommerce->countries->states[trim($package['destination']['state'])]; 484 485 486 487 break; 488 489 } 490 491 } 492 493 } 494 495 } 496 497 498 574 575 //Get Cart Quantity 576 $cartQuantity = $woocommerce->cart->cart_contents_count; 577 499 578 500 579 //PostNumber 501 580 $pcode =$package['destination']['postcode']; 502 $postcount=$this->settings['per_postcode_count']; 503 504 if ($final_rate===false) { 505 506 for($i=1; $i<=$postcount; $i++){ 581 if($pcode != ''){ 507 582 508 $shipcode =$this->settings['per_postcode_'.$i.'_postcode']; 583 /** Method Title For Postcode Shipping*/ 584 $postcodeLabel=$this->settings['postcode_title']; 585 586 $postcount=$this->settings['per_postcode_count']; 587 588 if ($final_rate===false) { 509 589 510 $pcodes = explode(",",$shipcode); 511 512 $p=0; 513 514 foreach($pcodes as $pc) { 515 516 if($pcode == $pcodes[$p]){ 517 518 $final_rate=floatval($this->settings['per_postcode_'.$i.'_fee']); 519 520 $label=__('Postcode Shipping', $this->id); 521 522 break; 590 for($i=1; $i<=$postcount; $i++){ 591 592 $shipcode =$this->settings['per_postcode_'.$i.'_postcode']; 593 594 $pcodes = explode(",",$shipcode); 595 596 $p=0; 597 598 foreach($pcodes as $pc) { 599 600 $singlePostcode = $pcodes[$p]; //Postcode 601 602 $isMultiPostcodes = strpos($singlePostcode, "-"); 603 604 //IF Bulk Of Postcodes Separated With "-" 605 if ($isMultiPostcodes === false) { 606 607 $postCode=$singlePostcode; //Postcode 608 if($pcode == $postCode){ 609 610 //Is Qantity Based Price shipping 611 $isMultiPrices = strpos($this->settings['per_postcode_'.$i.'_fee'], "|"); 612 613 if ($isMultiPrices === false) { 614 615 $final_rate=floatval($this->settings['per_postcode_'.$i.'_fee']); 616 617 $label=$label=__($postcodeLabel, $this->id); 618 619 break; 620 }else{ 621 622 //Get Price By Quantity 623 $final_rate = $this->calPriceByQuantity($cartQuantity,$this->settings['per_postcode_'.$i.'_fee']); 624 625 $label=$label=__($postcodeLabel, $this->id); 626 627 break; 628 } 629 630 } 631 632 }else{ 633 634 $getPostcode=$this->getPostcode($pcode,$singlePostcode); 635 636 if($pcode == $getPostcode){ 637 638 //Is Qantity Based Price shipping 639 $isMultiPrices = strpos($this->settings['per_postcode_'.$i.'_fee'], "|"); 640 641 if ($isMultiPrices === false) { 642 643 $final_rate=floatval($this->settings['per_postcode_'.$i.'_fee']); 644 645 $label=$label=__($postcodeLabel, $this->id); 646 647 break; 648 }else{ 649 650 //Get Price By Quantity 651 $final_rate = $this->calPriceByQuantity($cartQuantity,$this->settings['per_postcode_'.$i.'_fee']); 652 653 $label=$label=__($postcodeLabel, $this->id); 654 655 break; 656 } 657 } 658 659 660 661 } 662 663 $p++; 523 664 } 524 $p++;525 665 } 526 666 } … … 528 668 529 669 670 //State 671 672 if ($final_rate===false) { 673 674 /** Method Title For State Shipping*/ 675 $stateLabel=$this->settings['state_title']; 676 677 $count=$this->settings['per_state_count']; 678 679 for($i=1; $i<=$count; $i++){ 680 681 if (is_array($this->settings['per_state_'.$i.'_state'])) { 682 683 if (in_array(trim($package['destination']['state']), $this->settings['per_state_'.$i.'_state'])) { 684 685 686 //Is Qantity Based Price shipping 687 $isMultiPrices = strpos($this->settings['per_state_'.$i.'_fee'], "|"); 688 689 if ($isMultiPrices === false) { 690 691 $final_rate=floatval($this->settings['per_state_'.$i.'_fee']); 692 693 $label=$label=__($stateLabel, $this->id); 694 695 break; 696 }else{ 697 698 //Get Price By Quantity 699 $final_rate = $this->calPriceByQuantity($cartQuantity,$this->settings['per_state_'.$i.'_fee']); 700 701 $label=$label=__($stateLabel, $this->id); 702 703 break; 704 } 705 706 } 707 708 } 709 710 } 711 712 } 713 714 715 //Country 716 if ($final_rate===false) { 717 718 /** Method Title For Country Shipping*/ 719 $countryLabel=$this->settings['country_title']; 720 721 $count=$this->settings['per_country_count']; 722 723 for($i=1; $i<=$count; $i++){ 724 725 if (is_array($this->settings['per_country_'.$i.'_country'])) { 726 727 if (in_array(trim($package['destination']['country']), $this->settings['per_country_'.$i.'_country'])) { 728 729 //Is Qantity Based Price shipping 730 $isMultiPrices = strpos($this->settings['per_country_'.$i.'_fee'], "|"); 731 732 if ($isMultiPrices === false) { 733 734 $final_rate=floatval($this->settings['per_country_'.$i.'_fee']); 735 736 $label=$label=__($countryLabel, $this->id); 737 738 break; 739 }else{ 740 741 //Get Price By Quantity 742 $final_rate = $this->calPriceByQuantity($cartQuantity,$this->settings['per_country_'.$i.'_fee']); 743 744 $label=$label=__($countryLabel, $this->id); 745 746 break; 747 } 748 749 } 750 751 } 752 753 } 754 } 755 756 757 530 758 531 759 //Rest of the World … … 534 762 $final_rate=floatval($this->settings['fee_world']); 535 763 536 $label=__( 'worldwide postcode shipping', $this->id);764 $label=__($commonLabel, $this->id); 537 765 538 766 } -
postcode-shipping/trunk/readme.txt
r893119 r913504 1 1 === Postcode Shipping Rates- WooCommerce === 2 2 Author: Rizwan Ahammad 3 Tags: shipping, tax, rates, postcode, delivery, flatrate, flat, cost, free, state, country, world, methods, ecommerce, e-commerce, commerce, wordpress ecommerce, affiliate, store, sales, sell, shop, shopping, cart, checkout, configurable, variable, widgets3 Tags: shipping, tax, rates, postcode, delivery, flatrate, flat, cost, free, state, country, quantity, world, methods, ecommerce, e-commerce, commerce, wordpress ecommerce, affiliate, store, sales, sell, shop, shopping, cart, checkout, configurable, variable, widgets 4 4 Requires at least: 3.5 5 Tested up to: 3. 86 Stable tag: 1.05 Tested up to: 3.9.1 6 Stable tag: 2.0 7 7 License: GPLv3 8 8 License URI: http://www.gnu.org/licenses/gpl-3.0.html 9 9 10 Postcode Shipping is a clean, powerful shipping rates plugin that helps you define shipping rate per order on countrys/states/postcodes.10 Postcode Shipping is a clean, powerful shipping rates plugin that helps you define multiple rates based on Quantity/Order on countrys/states/postcodes and apply rates between 2 postcode zones. 11 11 12 12 == Description == 13 13 14 If you want to apply shipping rates based on country or state or postcode/zip Postcode shipping rates plugin lets you define a standard rate per order .14 If you want to apply shipping rates based on country or state or postcode/zip Postcode shipping rates plugin lets you define a standard rate per order/quantity. 15 15 16 If you set a rate for the client's country it will be Apply. If you set a rate for client's state it will be Apply. Otherwise, if you set a rate for client's Zip/postcode it will be Apply.If none of the rates are set, the "Rest of the World" rate will be Apply.16 if you set a rate for client's Zip/postcode it will be Apply. If you set a rate for client's state it will be Apply. If you set a rate for the client's country it will be Apply. Otherwise, If none of the rates are set, the "Rest of the World" rate will be Apply. 17 17 18 18 … … 29 29 = FEATURES = 30 30 31 * __Shipping Rates On Countrys__ - You can apply shipping rates on specific countrysor31 * __Shipping Rates on Postcode/Zip__ - You can apply shipping rates on specific postcodes and choose one or more postcodes for one rule. Separate codes with a comma or 32 32 * __Shipping Rates On State__ - You can apply shipping rates on specific states or 33 * __Shipping Rates on Postcode/Zip__ - You can apply shipping rates on specific postcodes and choose one or more postcodes for one rule. Separate codes with a comma 33 * __Shipping Rates On Countrys__ - You can apply shipping rates on specific countrys 34 *__Add Shipping Method Title__ - You can add method titles for all 4 methods postcode,country,state,worldwide 35 *__Apply Shipping Rates By Quantity__ - You can apply shipping rates on quantity for all postcode/state/country methods 36 37 example for price by quantity- Quantity|Price,Quantity|Price - 1|9.99,2|10.00 ect. if quantity exceeds more than given last price will apply i.e 10.00 38 34 39 example- 123456, 23456 ect 35 40 * __Shipping Rates On Rest Of World__ - Ship your items using a flat cost on worldwide. … … 77 82 == Changelog == 78 83 84 = 2.0 = 85 * You can add method titles for all 4 methods postcode,country,state,worldwide 86 * Add postcode between 2 zones like 00050-00080 87 * Define multiple rates based on Quantity 88 * Few minor bugs are fixed 89 79 90 = 1.0 = 80 91 * Initial release
Note: See TracChangeset
for help on using the changeset viewer.