Plugin Directory

Changeset 820990


Ignore:
Timestamp:
12/13/2013 11:20:02 AM (12 years ago)
Author:
Shipster
Message:

changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • baggage-freight/trunk/class-wc-baggagefreight.php

    r808788 r820990  
    11<?php
    2 add_action('plugins_loaded', 'init_baggage_shipping', 0);
     2
     3
     4
    35 
    46
     7 add_action('plugins_loaded', 'init_baggage_shipping', 0);
     8
     9 
     10
     11
     12
    513function init_baggage_shipping() {
    614
     15
     16
    717    if ( ! class_exists( 'WC_Shipping_Method' ) ) return;
     18
    819class WC_BF_Shipping extends WC_Shipping_Method {
    920
     21
     22
    1023    /**
     24
    1125     * __construct function.
     26
    1227     *
     28
    1329     * @access public
     30
    1431     * @return void
     32
    1533     */
     34
    1635    function __construct() {
     36
    1737        $this->id           = 'bf_shipping';
     38
    1839        $this->method_title = __('Baggage Freight Shipping', 'woocommerce');
     40
    1941        $this->init();
     42
    2043    }
    2144
     45
     46
    2247    /**
     48
    2349     * init function.
     50
    2451     *
     52
    2553     * @access public
     54
    2655     * @return void
     56
    2757     */
     58
    2859    function init() {
     60
    2961        // Load the form fields.
     62
    3063        $this->init_form_fields();
    3164
     65
     66
    3267        // Load the settings.
     68
    3369        $this->init_settings();
    3470
     71
     72
    3573        // Define user set variables
     74
    3675       /* $this->enabled        = $this->settings['enabled'];
     76
    3777        $this->title        = $this->settings['title'];
     78
    3879        $this->min_amount   = $this->settings['min_amount'];
     80
    3981        $this->availability = $this->settings['availability'];
     82
    4083        $this->countries    = $this->settings['countries'];
     84
    4185        $this->requires_coupon  = $this->settings['requires_coupon'];
     86
    4287        */
    43        
     88
     89       
     90
    4491        $this->title        = $this->get_option( 'title' );
     92
    4593        $this->type         = $this->get_option( 'type' );
     94
    4695        $this->fee          = $this->get_option( 'fee' );
     96
    4797        $this->type         = $this->get_option( 'type' );
     98
    4899        $this->codes        = $this->get_option( 'codes' );
     100
    49101        $this->availability = $this->get_option( 'availability' );
     102
    50103        $this->countries    = $this->get_option( 'countries' );
     104
    51105        // Actions
     106
    52107        add_action('woocommerce_update_options_shipping_'.$this->id, array(&$this, 'process_admin_options'));
     108
    53109    }
    54110
    55111
     112
     113
     114
    56115    /**
     116
    57117     * Initialise Gateway Settings Form Fields
     118
    58119     *
     120
    59121     * @access public
     122
    60123     * @return void
     124
    61125     */
     126
    62127    function init_form_fields() {
     128
    63129        global $woocommerce;
    64         global $wpdb;
    65        
     130
     131
     132
    66133        $this->form_fields = array(
     134
    67135            'enabled' => array(
     136
    68137                            'title'         => __( 'Enable/Disable', 'woocommerce' ),
     138
    69139                            'type'          => 'checkbox',
     140
    70141                            'label'         => __( 'Enable Baggage Freight Shipping', 'woocommerce' ),
     142
    71143                            'default'       => 'yes'
     144
    72145                        ),
     146
    73147            'title' => array(
     148
    74149                            'title'         => __( 'Method Title', 'woocommerce' ),
     150
    75151                            'type'          => 'text',
     152
    76153                            'description'   => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
     154
    77155                            'default'       => __( 'Baggage Freight Shipping', 'woocommerce' )
     156
    78157                        ),
     158
    79159           
     160
    80161            'availability' => array(
     162
    81163                            'title'         => __( 'Method availability', 'woocommerce' ),
     164
    82165                            'type'          => 'select',
     166
    83167                            'default'       => 'all',
     168
    84169                            'class'         => 'availability',
     170
    85171                            'options'       => array(
     172
    86173                                'all'       => __('All allowed countries', 'woocommerce'),
     174
    87175                                'specific'  => __('Specific Countries', 'woocommerce')
     176
    88177                            )
     178
    89179                        ),
     180
    90181            'countries' => array(
     182
    91183                            'title'         => __( 'Specific Countries', 'woocommerce' ),
     184
    92185                            'type'          => 'multiselect',
     186
    93187                            'class'         => 'chosen_select',
     188
    94189                            'css'           => 'width: 450px;',
     190
    95191                            'default'       => '',
     192
    96193                            'options'       => $woocommerce->countries->countries
     194
    97195                        )
     196
    98197            );
    99198
     199
     200
    100201    }
    101202
    102203
     204
     205
     206
    103207    /**
     208
    104209     * Admin Panel Options
     210
    105211     * - Options for bits like 'title' and availability on a country-by-country basis
     212
    106213     *
     214
    107215     * @since 1.0.0
     216
    108217     * @access public
     218
    109219     * @return void
     220
    110221     */
     222
    111223    public function admin_options() {
    112224
     225
     226
    113227        ?>
     228
    114229        <h3><?php _e('Baggage Freight Shipping', 'woocommerce'); ?></h3>
     230
    115231        <p><?php _e('Baggage Freight Shipping ', 'woocommerce'); ?></p>
     232
    116233        <table class="form-table">
     234
    117235        <?php
     236
    118237            $this->generate_settings_html();
     238
    119239        ?>
     240
    120241        </table>
     242
    121243        <?php
    122        
     244
     245       
     246
    123247    }
    124248
    125249
     250
     251
     252
    126253 
     254
    127255    function is_available( $package ) {
     256
    128257        global $woocommerce;
     258
     259
     260
     261        if ( $this->enabled == "no" ) return false;
     262
     263
     264
     265        $ship_to_countries = '';
     266
     267
     268
     269        if ( $this->availability == 'specific' ) {
     270
     271            $ship_to_countries = $this->countries;
     272
     273        } else {
     274
     275            if ( get_option('woocommerce_allowed_countries') == 'specific' )
     276
     277                $ship_to_countries = get_option('woocommerce_specific_allowed_countries');
     278
     279        }
     280
     281
     282
     283        if ( is_array( $ship_to_countries ) )
     284
     285            if ( ! in_array( $package['destination']['country'], $ship_to_countries ) )
     286
     287                return false;
     288
     289
     290
     291        // Enabled logic
     292
     293        $is_available = true;
     294
     295
     296
     297        if ( $this->requires_coupon == "yes" ) {
     298
     299
     300
     301            if ( $woocommerce->cart->applied_coupons ) {
     302
     303                foreach ($woocommerce->cart->applied_coupons as $code) {
     304
     305                    $coupon = new WC_Coupon( $code );
     306
     307
     308
     309                    if ( $coupon->enable_free_shipping() )
     310
     311                        return true;
     312
     313                }
     314
     315            }
     316
     317
     318
     319            // No coupon found, as it stands, free shipping is disabled
     320
     321            $is_available = false;
     322
     323
     324
     325        }
     326
     327
     328
     329        if ( isset( $woocommerce->cart->cart_contents_total ) && ! empty( $this->min_amount ) ) {
     330
     331
     332
     333            if ( $woocommerce->cart->prices_include_tax )
     334
     335                $total = $woocommerce->cart->tax_total + $woocommerce->cart->cart_contents_total;
     336
     337            else
     338
     339                $total = $woocommerce->cart->cart_contents_total;
     340
     341
     342
     343            if ( $this->min_amount > $total )
     344
     345                $is_available = false;
     346
     347            else
     348
     349                $is_available = true;
     350
     351
     352
     353        }
     354
     355
     356
     357        return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $is_available );
     358
     359    }
     360
     361
     362
     363
     364
     365    /**
     366
     367     * calculate_shipping function.
     368
     369     *
     370
     371     * @access public
     372
     373     * @return array
     374
     375     */
     376
     377    function calculate_shipping($package = array() )
     378
     379    {
     380
     381       
     382
     383        global $woocommerce;
     384
    129385        global $wpdb;
    130386
    131         if ( $this->enabled == "no" ) return false;
    132 
    133         $ship_to_countries = '';
    134 
    135         if ( $this->availability == 'specific' ) {
    136             $ship_to_countries = $this->countries;
    137         } else {
    138             if ( get_option('woocommerce_allowed_countries') == 'specific' )
    139                 $ship_to_countries = get_option('woocommerce_specific_allowed_countries');
    140         }
    141 
    142         if ( is_array( $ship_to_countries ) )
    143             if ( ! in_array( $package['destination']['country'], $ship_to_countries ) )
    144                 return false;
    145 
    146         // Enabled logic
    147         $is_available = true;
    148 
    149         if ( $this->requires_coupon == "yes" ) {
    150 
    151             if ( $woocommerce->cart->applied_coupons ) {
    152                 foreach ($woocommerce->cart->applied_coupons as $code) {
    153                     $coupon = new WC_Coupon( $code );
    154 
    155                     if ( $coupon->enable_free_shipping() )
    156                         return true;
     387        $prefix = $wpdb->prefix;
     388
     389        $sql = "select * from baggage_storeowner";
     390
     391        $res = mysql_query($sql);
     392
     393        $row = mysql_fetch_assoc($res);
     394
     395       
     396
     397       
     398
     399       
     400
     401        $sql_setting = "select * from baggage_settings";
     402
     403        $res_setting = mysql_query($sql_setting);
     404
     405       
     406
     407        if(mysql_num_rows($res_setting))
     408
     409        {
     410
     411            $row_setting = mysql_fetch_assoc($res_setting);
     412
     413            $package_type = $row_setting["package_type"];
     414
     415            $hfee = floatval($row_setting["hfee"]);
     416
     417        }
     418
     419        else
     420
     421        {
     422
     423            $package_type = "0";
     424
     425            $hfee = "0.00";
     426
     427        }
     428
     429       
     430
     431        $sql_dimension = "select * from baggage_dimensions";
     432
     433        $res_dimension = mysql_query($sql_dimension);
     434
     435        if(mysql_num_rows($res_dimension))
     436
     437        {
     438
     439          $row_dimension = mysql_fetch_assoc($res_dimension);
     440
     441          $d_Height = $row_dimension["height"];
     442
     443          $d_width  = $row_dimension["width"];
     444
     445          $d_length = $row_dimension["length"];
     446
     447        }
     448
     449        else
     450
     451        {
     452
     453          $d_Height = "10";
     454
     455          $d_width = "10";
     456
     457          $d_length = "10"; 
     458
     459        }
     460
     461   
     462
     463       
     464
     465   
     466
     467        $CollectCountry = $row["CollectCountry"];
     468
     469        $strUrl = "http://www.baggagefreight.com.au/api/getCountryName.aspx?countryid=".$CollectCountry;
     470
     471        $cCountry = trim(file_get_contents($strUrl));
     472
     473        $cCity = trim($row["CollectCity"]);
     474
     475        $cState = trim($row["CollectState"]);
     476
     477        $cPin = trim($row["CollectZip"]);
     478
     479       
     480
     481        $Weight = "";
     482
     483        $Length = "";
     484
     485        $Width  = "";
     486
     487        $Height = "";
     488
     489        $Unit = "";
     490
     491        $Desc = "";
     492
     493       
     494
     495       
     496
     497        $packedsku = '';
     498
     499        $totweight = 0;
     500
     501        $j=1;
     502
     503        $k=0;
     504
     505        $packeditem = NULL;
     506
     507       
     508
     509       
     510
     511        $Amount =$woocommerce->cart->subtotal;
     512
     513   
     514
     515       
     516
     517        $loop = 0;
     518
     519       
     520
     521        foreach ( $woocommerce->cart->get_cart() as $itms )
     522
     523        {
     524
     525           $product_id = $itms["product_id"];
     526
     527           $quantity = $itms["quantity"];
     528
     529   
     530
     531           
     532
     533           $post_data = get_post($product_id);
     534
     535           $product_title = $post_data->post_title;
     536
     537           
     538
     539           $sql_SKU = "select meta_value from ".$prefix."postmeta where post_id=".$product_id." and meta_key='_sku'";
     540
     541           $res_Sku = mysql_query($sql_SKU);
     542
     543           $row_sku = mysql_fetch_assoc($res_Sku);
     544
     545           $sku = $row_sku["meta_value"];
     546
     547           
     548
     549           $strDestCountry = get_post_meta($product_id, '_shipping_country', true);
     550
     551           
     552         
     553           
     554
     555           if($package_type=="1")
     556
     557           {
     558
     559              $W = get_post_meta($product_id, '_weight', true);
     560
     561              $L = get_post_meta($product_id, '_length', true);
     562
     563              $Wi = get_post_meta($product_id, '_width', true);
     564
     565              $H = get_post_meta($product_id, '_height', true);
     566
     567           }
     568
     569           else
     570
     571           {
     572
     573               $sql = "select * from baggage_excel where SKU='$sku'";
     574
     575               $res = mysql_query($sql);
     576
     577               $row = mysql_fetch_assoc($res);
     578
     579               
     580
     581               $W = $row["Weight"];
     582
     583               $L = $row["Length"];
     584
     585               $Wi = $row["Width"];
     586
     587               $H = $row["Height"];
     588
     589           }
     590
     591           
     592
     593           
     594
     595           if($L == "")
     596
     597           {
     598
     599              $L = $d_length; 
     600
     601           }
     602
     603           
     604
     605           if($Wi == "")
     606
     607           {
     608
     609              $Wi = $d_width; 
     610
     611           }
     612
     613           
     614
     615           if($H == "")
     616
     617           {
     618
     619              $H = $d_height; 
     620
     621           }
     622
     623           
     624
     625           $row_packtype = mysql_fetch_array(mysql_query("select * from baggage_product_pack where SKU='$sku'"));
     626           
     627       
     628         
     629   
     630
     631           if($row_packtype['packType']==1)
     632
     633           {
     634
     635               
     636
     637              $packeditem[$loop] = array(
     638
     639                    "sku" => $sku,
     640
     641                    "l" => $L,
     642
     643                    "w" => $Wi,
     644
     645                    "h" => $H,
     646
     647                    "weight" => $W,
     648
     649                    "type" =>$row_packtype['packType'],
     650
     651                    "qty" =>$quantity,
     652
     653                 );
     654
     655                 
     656
     657                 $loop++;
     658
     659             
     660
     661           }
     662
     663           else
     664
     665           {
     666
     667                for($i=1;$i<=$quantity;$i++)
     668
     669                {
     670
     671                         $Weight = $Weight.$W.",";
     672
     673                         $Length = $Length.$L.",";
     674
     675                         $Width  = $Width.$Wi.",";
     676
     677                         $Height = $Height.$H.",";
     678
     679                         $Unit   = $Unit."cm,";
     680
     681                         $strDescription = $sku;
     682
     683                         if(strlen($strDescription) > 30)
     684
     685                         {
     686
     687                            $strDescription = substr($strDescription, 0, 29);
     688
     689                         }
     690
     691                         
     692
     693                         $strDescription = str_replace(",","",$strDescription);
     694
     695                         
     696
     697                         $Desc   = $Desc.$strDescription.",";   
     698
     699                             
     700
     701                 }
     702
     703           }
     704
     705       
     706
     707   
     708
     709        }
     710
     711       
     712
     713       
     714
     715        /*********************** Start Calculation for packed***********************/
     716
     717         
     718
     719          if(count($packeditem)>0)
     720
     721          {
     722
     723                /*for($p=0; $p<count($product);$p++)
     724
     725                {
     726
     727                    if($product[$p]['type']==1){ $packeditem[] = $product[$p];}
     728
     729                    if($product[$p]['type']==0){$unpackeditem[] = $product[$p];}
     730
     731                }*/
     732
     733   
     734
     735                for($pkd=0; $pkd<count($packeditem);$pkd++)
     736
     737                {
     738
     739                    if($packeditem[$pkd]["qty"]>1) {$packedsku .= $j.".".$packeditem[$pkd]["sku"]."(".$packeditem[$pkd]["qty"]."items) ";}
     740
     741                    else{ $packedsku .= $j.".".$packeditem[$pkd]["sku"]." "; }
     742
     743                   
     744
     745                    $totweight = $totweight+($packeditem[$pkd]["weight"]*$packeditem[$pkd]["qty"]);
     746
     747                   
     748
     749                    for($q=1; $q<=$packeditem[$pkd]['qty'];$q++)
     750
     751                    {
     752
     753                        $numbers = array($packeditem[$pkd]['l'],$packeditem[$pkd]['w'],$packeditem[$pkd]['h']);
     754
     755                        rsort($numbers);
     756
     757                       
     758
     759                        foreach ($numbers as $key => $val)
     760
     761                        {  $sortdimension[$k][$key] = $val; }
     762
     763                        $k++;   
     764
     765                    }
     766
     767                    $j++;   
     768
    157769                }
    158             }
    159 
    160             // No coupon found, as it stands, free shipping is disabled
    161             $is_available = false;
    162 
    163         }
    164 
    165         if ( isset( $woocommerce->cart->cart_contents_total ) && ! empty( $this->min_amount ) ) {
    166 
    167             if ( $woocommerce->cart->prices_include_tax )
    168                 $total = $woocommerce->cart->tax_total + $woocommerce->cart->cart_contents_total;
    169             else
    170                 $total = $woocommerce->cart->cart_contents_total;
    171 
    172             if ( $this->min_amount > $total )
    173                 $is_available = false;
    174             else
    175                 $is_available = true;
    176 
    177         }
    178 
    179         return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $is_available );
    180     }
    181 
    182 
    183     /**
    184      * calculate_shipping function.
    185      *
    186      * @access public
    187      * @return array
    188      */
    189     function calculate_shipping($package = array() )
    190     {
    191      
    192         global $woocommerce;
    193         global $wpdb;
    194        
    195         $prefix = $wpdb->prefix;
    196         $sql = "select * from baggage_storeowner";
    197         $row = $wpdb->get_row($sql, OBJECT);
     770
     771               
     772
     773               
     774
     775                for($sort = 0; $sort<count($sortdimension); $sort++)
     776
     777                {
     778
     779                    $alllength[] =  $sortdimension[$sort][0];
     780
     781                    $allwidth[] =  $sortdimension[$sort][1];
     782
     783                    $allheight[] =  $sortdimension[$sort][2];
     784
     785                }
     786
     787             
     788
     789                $tot_height = 0;
     790
     791                for($i = 0; $i<count($allheight); $i++)
     792
     793                {
     794
     795                  $tot_height = $tot_height+$allheight[$i] ;
     796
     797                }
     798
     799               
     800
     801                $item["packed"]["sku"] = $packedsku;
     802
     803                $item["packed"]["l"] =  max($alllength);
     804
     805                $item["packed"]["w"] =  max($allwidth);
     806
     807                $item["packed"]["h"] = $tot_height;
     808
     809                $item["packed"]["weight"] = $totweight;
     810
     811                $item["packed"]["unit"] = "cm";
     812
     813       
     814
     815          }
     816
    198817         
    199        
    200         $sql_setting = "select * from baggage_settings";
    201         $res_setting_count = $wpdb->get_row($sql_setting, OBJECT); 
    202        
    203         if(count($res_setting_count))
    204         {
    205             $row_setting =  $wpdb->get_row($sql_setting, OBJECT);
    206              $package_type = $row_setting->package_type;
    207             $hfee = floatval($row_setting->hfee);
    208         }
    209         else
    210         {
    211             $package_type = "1";
    212             $hfee = "0.00";
    213         }
    214        
    215         $sql_dimension = "select * from baggage_dimensions";
    216         $res_dimension_count =  $wpdb->get_row($sql_dimension, OBJECT);
    217         if(count($res_dimension_count))
    218         {
    219                   $row_dimension = $wpdb->get_row($sql_dimension, OBJECT);
    220                   $d_Height = $row_dimension->height;
    221                   $d_width  = $row_dimension->width;
    222                   $d_length = $row_dimension->length;
    223         }
    224         else
    225         {
    226                 $d_Height = "10";
    227                 $d_width = "10";
    228                 $d_length = "10"; 
    229                 $d_weight = "10";
    230         }
    231    
    232        
    233    
    234         $CollectCountry = $row->CollectCountry;
    235         $strUrl = "http://www.baggagefreight.com.au/api/getCountryName.aspx?countryid=".$CollectCountry;
    236         $cCountry = trim(file_get_contents($strUrl));
    237         $cCity = trim($row->CollectCity);
    238         $cState = trim($row->CollectState);
    239         $cPin = trim($row->CollectZip);
    240        
    241         $Weight = "";
    242         $Length = "";
    243         $Width  = "";
    244         $Height = "";
    245         $Unit = "";
    246         $Desc = "";
    247        
    248        
    249         $packedsku = '';
    250         $totweight = 0;
    251         $j=1;
    252         $k=0;
    253         $packeditem = NULL;
    254        
    255        
    256         $Amount =$woocommerce->cart->subtotal;
    257    
    258        
    259         $loop = 0;
    260        
    261         foreach ( $woocommerce->cart->get_cart() as $itms )
    262         {
    263            $product_id = $itms["product_id"];
    264            $quantity = $itms["quantity"];
    265    
    266            
    267            $post_data = get_post($product_id);
    268            $product_title = $post_data->post_title;
    269            
    270            $sql_SKU = "select meta_value from ".$prefix."postmeta where post_id=".$product_id." and meta_key='_sku'";
    271            $row_sku = $wpdb->get_row($sql_SKU, OBJECT); 
    272            $sku = $row_sku->meta_value;
    273      
    274            $strDestCountry = get_post_meta($product_id, '_shipping_country', true);
    275            
    276            
    277            if($package_type=="1")
    278            {
    279               $W = get_post_meta($product_id, '_weight', true);
    280               $L = get_post_meta($product_id, '_length', true);
    281               $Wi = get_post_meta($product_id, '_width', true);
    282               $H = get_post_meta($product_id, '_height', true);
    283            }
    284            else
    285            {
    286                $sql = "select * from baggage_excel where SKU='$sku'";
    287                $row = $wpdb->get_row($sql, OBJECT);
    288          
    289                $W = $row->Weight;
    290                $L = $row->Length;
    291                $Wi = $row->Width;
    292                $H = $row->Height;
    293            }
    294            
    295            
    296            if($L == "")
    297            {
    298               $L = $d_length; 
    299            }
    300            
    301            if($Wi == "")
    302            {
    303               $Wi = $d_width; 
    304            }
    305            
    306            if($H == "")
    307            {
    308               $H = $d_height; 
    309            }
    310            
    311               if($W == "")
    312            {
    313               $W = $d_weight; 
    314            }
    315            
    316            $row_packtype = $wpdb->get_row("select * from baggage_product_pack where SKU='$sku'");
    317    
    318            if($row_packtype->packType==1)
    319            {
    320                
    321                    $packeditem[$loop] = array(
    322                     "sku" => $sku,
    323                     "l" => $L,
    324                     "w" => $Wi,
    325                     "h" => $H,
    326                     "weight" => $W,
    327                     "type" =>$row_packtype->packType,
    328                     "qty" =>$quantity,
    329                  );
    330                  
    331                  $loop++;
    332              
    333            }
    334            else
    335            {
    336                 for($i=1;$i<=$quantity;$i++)
    337                 {
    338                          $Weight = $Weight.$W.",";
    339                          $Length = $Length.$L.",";
    340                          $Width  = $Width.$Wi.",";
    341                          $Height = $Height.$H.",";
    342                          $Unit   = $Unit."cm,";
    343                          $strDescription = $sku;
    344                          if(strlen($strDescription) > 30)
    345                          {
    346                             $strDescription = substr($strDescription, 0, 29);
    347                          }
    348                          
    349                          $strDescription = str_replace(",","",$strDescription);
    350                          
    351                          $Desc   = $Desc.$strDescription.",";   
    352                              
    353                  }
    354            }
    355        
    356    
    357         }
    358        
    359        
    360         /*********************** Start Calculation for packed***********************/
    361          
    362           if(count($packeditem)>0)
    363           {
    364                 /*for($p=0; $p<count($product);$p++)
    365                 {
    366                     if($product[$p]['type']==1){ $packeditem[] = $product[$p];}
    367                     if($product[$p]['type']==0){$unpackeditem[] = $product[$p];}
    368                 }*/
    369    
    370                 for($pkd=0; $pkd<count($packeditem);$pkd++)
    371                 {
    372                     if($packeditem[$pkd]["qty"]>1) {$packedsku .= $j.".".$packeditem[$pkd]["sku"]."(".$packeditem[$pkd]["qty"]."items) ";}
    373                     else{ $packedsku .= $j.".".$packeditem[$pkd]["sku"]." "; }
    374                    
    375                     $totweight = $totweight+($packeditem[$pkd]["weight"]*$packeditem[$pkd]["qty"]);
    376                    
    377                     for($q=1; $q<=$packeditem[$pkd]['qty'];$q++)
    378                     {
    379                         $numbers = array($packeditem[$pkd]['l'],$packeditem[$pkd]['w'],$packeditem[$pkd]['h']);
    380                         rsort($numbers);
    381                        
    382                         foreach ($numbers as $key => $val)
    383                         {  $sortdimension[$k][$key] = $val; }
    384                         $k++;   
    385                     }
    386                     $j++;   
    387                 }
    388                
    389                
    390                 for($sort = 0; $sort<count($sortdimension); $sort++)
    391                 {
    392                     $alllength[] =  $sortdimension[$sort][0];
    393                     $allwidth[] =  $sortdimension[$sort][1];
    394                     $allheight[] =  $sortdimension[$sort][2];
    395                 }
    396              
    397                 $tot_height = 0;
    398                 for($i = 0; $i<count($allheight); $i++)
    399                 {
    400                   $tot_height = $tot_height+$allheight[$i] ;
    401                 }
    402                
    403                 $item["packed"]["sku"] = $packedsku;
    404                 $item["packed"]["l"] =  max($alllength);
    405                 $item["packed"]["w"] =  max($allwidth);
    406                 $item["packed"]["h"] = $tot_height;
    407                 $item["packed"]["weight"] = $totweight;
    408                 $item["packed"]["unit"] = "cm";
    409        
    410           }
    411          
    412        
     818
     819       
     820
    413821          /*********************** End Calculation for packed***********************/
    414        
     822
     823       
     824
    415825        $Weight = $Weight.$item["packed"]["weight"].",";
     826
    416827        $Length = $Length.$item["packed"]["l"].",";
     828
    417829        $Width  = $Width.$item["packed"]["w"].",";
     830
    418831        $Height = $Height.$item["packed"]["h"].",";
     832
    419833        $Unit = $Unit.$item["packed"]["unit"].",";
     834
    420835        $Desc   = $Desc.$item["packed"]["sku"].",";
    421        
     836
     837       
     838
    422839        $Weight = substr($Weight, 0, -1);
    423840        if($Weight[strlen($Weight)-1]==",")
     
    450867           $Desc = substr($Desc, 0, -1);
    451868        }
     869
    452870   
    453        
     871
     872       
     873
    454874        $dCountry = trim($package["destination"]["country"]);   
     875
    455876        $dState = trim($package["destination"]["state"]);
     877
    456878        $dPin = trim($package["destination"]["postcode"]);
     879
    457880        $dCity = trim($package["destination"]["city"]);
    458        
     881
     882       
     883
    459884        $address = trim($package["destination"]["address"]);
     885
    460886        $address_2 = trim($package["destination"]["address_2"]);
    461        
     887
     888       
     889
    462890        $objC = new WC_Countries();
     891
    463892        $dCountry = trim($objC->countries[$dCountry]);
    464        
    465        
    466        
     893
     894       
     895
     896       
     897
     898       
     899
    467900          if($dPin!="")
     901
    468902          {
     903         
     904       
     905
    469906                $data = array(
     907
    470908                    'cCountry' => $cCountry, 
     909
    471910                    'cCity' => $cCity,     
     911
    472912                    'cState' => $cState,         
     913
    473914                    'cPin' => $cPin,
     915
    474916                    'dCountry' => $dCountry,   
     917
    475918                    'dState' => $dState,           
     919
    476920                    'dCity' => $dCity,       
     921
    477922                    'dPin' => $dPin,           
     923
    478924                    'Weight' => $Weight,         
     925
    479926                    'Length' => $Length,         
     927
    480928                    'Width' => $Width,           
     929
    481930                    'Height' => $Height,         
     931
    482932                    'Unit' => $Unit,             
     933
    483934                    'Amount' => $Amount 
     935
    484936                );   
     937
     938
    485939               
    486              
     940
     941                $ch = curl_init('http://www.baggagefreight.com.au/api/minrate.aspx');                                                       
     942
     943                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     944
     945                curl_setopt($ch, CURLOPT_POST, 1);                                               
     946
     947                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);                                                 
     948
     949                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                         
     950
     951                $result = curl_exec($ch);
     952
    487953               
    488                 $ch = curl_init('http://www.baggagefreight.com.au/api/minrate.aspx' );                                                       
    489                  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    490                 curl_setopt($ch, CURLOPT_POST, 1);                                               
    491                 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);                                                 
    492                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                         
    493                 $result = curl_exec($ch); 
     954
     955   
     956
    494957               
    495              
     958
    496959         
     960
    497961               if($result)
     962
    498963               {
     964
    499965               
     966
    500967                    $arrBFIShipping = explode(":",$result);
     968
    501969                    $ship_cost = floatval($arrBFIShipping[0]);
     970
    502971                    $_SESSION["bf_strBookingAmount"] = $ship_cost;
     972
    503973                    $carrier = $arrBFIShipping[1];
     974
    504975                    $_SESSION["bf_strCarrier"] = $carrier;
     976
    505977                    $service = $arrBFIShipping[2];
     978
    506979                    $_SESSION["bf_strService"] = $service;
     980
    507981                    $transit = $arrBFIShipping[4];
     982
    508983                   
     984
    509985                    $warranty = floatval($arrBFIShipping[5]);
     986
    510987                   
     988
    511989                    $arrTransit = explode(" ",$transit);
     990
    512991                    $transitTime = $arrTransit[0];
     992
    513993                    $_SESSION["bf_strTransitTime"] = $transitTime;
     994
    514995                    $_SESSION["bf_warranty"] = $warranty;
     996
    515997               
     998
    516999     
     1000
    5171001                    if(floatval($ship_cost)>0)
     1002
    5181003                    {
     1004
    5191005                       
     1006
    5201007                        $_SESSION["bf_Weight"] = $Weight;
     1008
    5211009                        $_SESSION["bf_Length"] = $Length;
     1010
    5221011                        $_SESSION["bf_Width"]  = $Width;
     1012
    5231013                        $_SESSION["bf_Height"] = $Height;
     1014
    5241015                        $_SESSION["bf_strDescription"]   = $Desc;
     1016
    5251017                        $_SESSION["bf_Unit"]   = $Unit;
     1018
    5261019                       
     1020
    5271021                        $_SESSION["bf_booking"] = "1";
     1022
    5281023                        $_SESSION["bf_strTotalBookingRate"] = $Amount;
     1024
    5291025                       
     1026
    5301027                       
     1028
    5311029                        $args= array(
     1030
    5321031                        'id'    => $this->id,
     1032
    5331033                        'label' => $service." (Without Transit Warranty)",
     1034
    5341035                        'cost'  => $ship_cost
     1036
    5351037                          );
     1038
    5361039                       
     1040
    5371041                       
     1042
    5381043                        $this->add_rate( $args );
     1044
    5391045                       
     1046
    5401047                       
     1048
    5411049                        if($warranty>0)
     1050
    5421051                        {
     1052
    5431053                          $ship_cost = $ship_cost+$warranty;
     1054
    5441055                       
     1056
    5451057                        $args= array(
     1058
    5461059                        'id'    => $this->id."1",
     1060
    5471061                        'label' => $service." (With Transit Warranty)",
     1062
    5481063                        'cost'  => $ship_cost
     1064
    5491065                          );
     1066
    5501067                          }
     1068
    5511069                       
     1070
    5521071                       
     1072
    5531073                        $this->add_rate( $args );
     1074
    5541075                    }
     1076
    5551077                }
     1078
    5561079            }
     1080
    5571081           
     1082
    5581083    }
    5591084
     1085
     1086
    5601087 }
    5611088
     1089
     1090
    5621091}
    5631092
     1093
     1094
    5641095function add_bf_shipping_method( $methods ) {
     1096
    5651097    $methods[] = 'WC_BF_Shipping';
     1098
    5661099    return $methods;
     1100
    5671101}
    5681102
     1103
     1104
    5691105function custom_woocommerce_billing_fields( $fields ) {
    5701106
    5711107
     1108
     1109
     1110
    5721111   /*$fields['billing_city']    = array(
     1112
    5731113      'label'          => __('Town/City', 'woocommerce'),
     1114
    5741115      'placeholder'    => _x('Town/City', 'placeholder', 'woocommerce'),
     1116
    5751117      'required'       => true,
     1118
    5761119      'class'          => array('form-row-first', 'update_totals_on_change')
     1120
    5771121   );*/
     1122
    5781123   
     1124
    5791125   $fields['billing_city']['class'] = array('form-row-first', 'update_totals_on_change');
     1126
    5801127   
     1128
    5811129 
    5821130
     1131
     1132
    5831133 return $fields;
     1134
    5841135}
    5851136
     1137
     1138
    5861139//add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
    5871140
     
    5891142
    5901143
     1144
     1145
     1146
     1147
     1148
    5911149function custom_woocommerce_shipping_fields( $fields ) {
    5921150
     1151
     1152
    5931153   /*$fields['shipping_city']   = array(
     1154
    5941155     'label'          => __('Town/City', 'woocommerce'),
     1156
    5951157      'placeholder'    => __('Town/City', 'placeholder', 'woocommerce'),
     1158
    5961159      'required'       => true,
     1160
    5971161      'class'          => array('form-row-first', 'update_totals_on_change')
     1162
    5981163   );*/
     1164
    5991165   
     1166
    6001167   $fields['shipping_city']['class'] = array('form-row-first','update_totals_on_change');
    6011168
     1169
     1170
    6021171 return $fields;
     1172
    6031173}
    6041174
     1175
     1176
    6051177//add_filter( 'woocommerce_shipping_fields', 'custom_woocommerce_shipping_fields');
    6061178
     
    6091181
    6101182
     1183
     1184
     1185
     1186
     1187
     1188
    6111189add_filter('woocommerce_shipping_methods', 'add_bf_shipping_method' );
Note: See TracChangeset for help on using the changeset viewer.