Plugin Directory

Changeset 913504


Ignore:
Timestamp:
05/13/2014 07:59:52 PM (12 years ago)
Author:
Rizwanahammad
Message:

Version 2.0

Location:
postcode-shipping/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • postcode-shipping/trunk/postcode_shipping.php

    r839225 r913504  
    11<?php
    22
     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
     25if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     26
     27
     28
    329/**
    430
    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 on WooCommerce.
    10 
    11  * Version: 1.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 
    29 /**
    30 
    3131 * Check if WooCommerce is active
    3232
     
    6767                $this->method_title         = __('Postcode Shipping', $this->id);
    6868
    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);
    7070
    7171                $this->wc_shipping_init();
     
    100100
    101101
    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'];
    105105
    106106
     
    134134
    135135                    ),
     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                    ),
    136156
    137157                    'title' => array(
     
    146166
    147167                    ),
    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                   
    168169
    169170                    'fee_world' => array(
     
    180181
    181182                    ),
     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                    ),
    182195
    183196                    'per_country_count' => array(
     
    192205
    193206                    ),
     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                    ),
    194219
    195220                    'per_state_count' => array(
     
    204229
    205230                    ),
     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                    ),
    206243
    207244                    'per_postcode_count' => array(
     
    271308                        'type'          => 'text',
    272309
    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),
    274311
    275312                        'default'       => '',
    276313
    277                         'placeholder'   =>  '0.0',
     314                        'placeholder'   =>  '1|10.00',
    278315
    279316                    );
     
    344381                        'type'          => 'text',
    345382
    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),
    347384
    348385                        'default'       => '',
    349386
    350                         'placeholder'   =>  '0.0',
     387                        'placeholder'   =>  '1|10.00',
    351388
    352389                    );
     
    364401            /* per PostNumber form fields*/
    365402
    366            
    367 
    368403            function init_shipping_fields_per_postcode() {
    369404
    370 
    371 
    372405                global $woocommerce;
    373 
    374                
    375 
     406               
    376407                $this->form_fields['per_postcode']=array(
    377408
     
    385416
    386417                               
    387 
    388418                $count=$this->settings['per_postcode_count'];               
    389419
    390420               
    391 
    392421                for($counter = 1; $count >= $counter; $counter++) {
    393422
     
    398427                        'type'      => 'textarea',
    399428
    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),
    401430
    402431                        'default'   => '',
    403432
    404                         'placeholder'   =>  '12345, 23456 ect',
     433                        'placeholder'   =>  '12345-12350,123456 ect',
    405434
    406435                    );
     
    412441                        'type'          => 'text',
    413442
    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),
    415444
    416445                        'default'       => '',
    417446
    418                         'placeholder'   =>  '0.0',
     447                        'placeholder'   =>  '1|10.00',
    419448
    420449                    );
     
    425454
    426455           
    427 
    428456            }
    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               
    432556            /* Calculate the rate */ 
    433557
     
    439563
    440564                $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
    444573                    $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                   
    499578                   
    500579                    //PostNumber
    501580                    $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 != ''){
    507582                           
    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) {
    509589                           
    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++;
    523664                                }
    524                             $p++;
    525665                            }
    526666                        }
     
    528668                   
    529669                   
     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                   
    530758                   
    531759                    //Rest of the World
     
    534762                        $final_rate=floatval($this->settings['fee_world']);
    535763
    536                         $label=__('worldwide postcode shipping', $this->id);
     764                        $label=__($commonLabel, $this->id);
    537765
    538766                    }
  • postcode-shipping/trunk/readme.txt

    r893119 r913504  
    11=== Postcode Shipping Rates- WooCommerce ===
    22Author: 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, widgets
     3Tags: 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
    44Requires at least: 3.5
    5 Tested up to: 3.8
    6 Stable tag: 1.0
     5Tested up to: 3.9.1
     6Stable tag: 2.0
    77License: GPLv3
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
    99
    10 Postcode Shipping is a clean, powerful shipping rates plugin that helps you define shipping rate per order on countrys/states/postcodes.
     10Postcode 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.
    1111
    1212== Description ==
    1313
    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.
     14If 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.
    1515
    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.
    1717
    1818
     
    2929= FEATURES =
    3030
    31 * __Shipping Rates On Countrys__ - You can apply shipping rates on specific countrys or
     31* __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
    3232* __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
     37example 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
    3439example- 123456, 23456 ect
    3540* __Shipping Rates On Rest Of World__ - Ship your items using a flat cost on worldwide.
     
    7782== Changelog ==
    7883
     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
    7990= 1.0  =
    8091* Initial release
Note: See TracChangeset for help on using the changeset viewer.