Changeset 820990
- Timestamp:
- 12/13/2013 11:20:02 AM (12 years ago)
- File:
-
- 1 edited
-
baggage-freight/trunk/class-wc-baggagefreight.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
baggage-freight/trunk/class-wc-baggagefreight.php
r808788 r820990 1 1 <?php 2 add_action('plugins_loaded', 'init_baggage_shipping', 0); 2 3 4 3 5 4 6 7 add_action('plugins_loaded', 'init_baggage_shipping', 0); 8 9 10 11 12 5 13 function init_baggage_shipping() { 6 14 15 16 7 17 if ( ! class_exists( 'WC_Shipping_Method' ) ) return; 18 8 19 class WC_BF_Shipping extends WC_Shipping_Method { 9 20 21 22 10 23 /** 24 11 25 * __construct function. 26 12 27 * 28 13 29 * @access public 30 14 31 * @return void 32 15 33 */ 34 16 35 function __construct() { 36 17 37 $this->id = 'bf_shipping'; 38 18 39 $this->method_title = __('Baggage Freight Shipping', 'woocommerce'); 40 19 41 $this->init(); 42 20 43 } 21 44 45 46 22 47 /** 48 23 49 * init function. 50 24 51 * 52 25 53 * @access public 54 26 55 * @return void 56 27 57 */ 58 28 59 function init() { 60 29 61 // Load the form fields. 62 30 63 $this->init_form_fields(); 31 64 65 66 32 67 // Load the settings. 68 33 69 $this->init_settings(); 34 70 71 72 35 73 // Define user set variables 74 36 75 /* $this->enabled = $this->settings['enabled']; 76 37 77 $this->title = $this->settings['title']; 78 38 79 $this->min_amount = $this->settings['min_amount']; 80 39 81 $this->availability = $this->settings['availability']; 82 40 83 $this->countries = $this->settings['countries']; 84 41 85 $this->requires_coupon = $this->settings['requires_coupon']; 86 42 87 */ 43 88 89 90 44 91 $this->title = $this->get_option( 'title' ); 92 45 93 $this->type = $this->get_option( 'type' ); 94 46 95 $this->fee = $this->get_option( 'fee' ); 96 47 97 $this->type = $this->get_option( 'type' ); 98 48 99 $this->codes = $this->get_option( 'codes' ); 100 49 101 $this->availability = $this->get_option( 'availability' ); 102 50 103 $this->countries = $this->get_option( 'countries' ); 104 51 105 // Actions 106 52 107 add_action('woocommerce_update_options_shipping_'.$this->id, array(&$this, 'process_admin_options')); 108 53 109 } 54 110 55 111 112 113 114 56 115 /** 116 57 117 * Initialise Gateway Settings Form Fields 118 58 119 * 120 59 121 * @access public 122 60 123 * @return void 124 61 125 */ 126 62 127 function init_form_fields() { 128 63 129 global $woocommerce; 64 global $wpdb; 65 130 131 132 66 133 $this->form_fields = array( 134 67 135 'enabled' => array( 136 68 137 'title' => __( 'Enable/Disable', 'woocommerce' ), 138 69 139 'type' => 'checkbox', 140 70 141 'label' => __( 'Enable Baggage Freight Shipping', 'woocommerce' ), 142 71 143 'default' => 'yes' 144 72 145 ), 146 73 147 'title' => array( 148 74 149 'title' => __( 'Method Title', 'woocommerce' ), 150 75 151 'type' => 'text', 152 76 153 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 154 77 155 'default' => __( 'Baggage Freight Shipping', 'woocommerce' ) 156 78 157 ), 158 79 159 160 80 161 'availability' => array( 162 81 163 'title' => __( 'Method availability', 'woocommerce' ), 164 82 165 'type' => 'select', 166 83 167 'default' => 'all', 168 84 169 'class' => 'availability', 170 85 171 'options' => array( 172 86 173 'all' => __('All allowed countries', 'woocommerce'), 174 87 175 'specific' => __('Specific Countries', 'woocommerce') 176 88 177 ) 178 89 179 ), 180 90 181 'countries' => array( 182 91 183 'title' => __( 'Specific Countries', 'woocommerce' ), 184 92 185 'type' => 'multiselect', 186 93 187 'class' => 'chosen_select', 188 94 189 'css' => 'width: 450px;', 190 95 191 'default' => '', 192 96 193 'options' => $woocommerce->countries->countries 194 97 195 ) 196 98 197 ); 99 198 199 200 100 201 } 101 202 102 203 204 205 206 103 207 /** 208 104 209 * Admin Panel Options 210 105 211 * - Options for bits like 'title' and availability on a country-by-country basis 212 106 213 * 214 107 215 * @since 1.0.0 216 108 217 * @access public 218 109 219 * @return void 220 110 221 */ 222 111 223 public function admin_options() { 112 224 225 226 113 227 ?> 228 114 229 <h3><?php _e('Baggage Freight Shipping', 'woocommerce'); ?></h3> 230 115 231 <p><?php _e('Baggage Freight Shipping ', 'woocommerce'); ?></p> 232 116 233 <table class="form-table"> 234 117 235 <?php 236 118 237 $this->generate_settings_html(); 238 119 239 ?> 240 120 241 </table> 242 121 243 <?php 122 244 245 246 123 247 } 124 248 125 249 250 251 252 126 253 254 127 255 function is_available( $package ) { 256 128 257 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 129 385 global $wpdb; 130 386 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 157 769 } 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 198 817 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 413 821 /*********************** End Calculation for packed***********************/ 414 822 823 824 415 825 $Weight = $Weight.$item["packed"]["weight"].","; 826 416 827 $Length = $Length.$item["packed"]["l"].","; 828 417 829 $Width = $Width.$item["packed"]["w"].","; 830 418 831 $Height = $Height.$item["packed"]["h"].","; 832 419 833 $Unit = $Unit.$item["packed"]["unit"].","; 834 420 835 $Desc = $Desc.$item["packed"]["sku"].","; 421 836 837 838 422 839 $Weight = substr($Weight, 0, -1); 423 840 if($Weight[strlen($Weight)-1]==",") … … 450 867 $Desc = substr($Desc, 0, -1); 451 868 } 869 452 870 453 871 872 873 454 874 $dCountry = trim($package["destination"]["country"]); 875 455 876 $dState = trim($package["destination"]["state"]); 877 456 878 $dPin = trim($package["destination"]["postcode"]); 879 457 880 $dCity = trim($package["destination"]["city"]); 458 881 882 883 459 884 $address = trim($package["destination"]["address"]); 885 460 886 $address_2 = trim($package["destination"]["address_2"]); 461 887 888 889 462 890 $objC = new WC_Countries(); 891 463 892 $dCountry = trim($objC->countries[$dCountry]); 464 465 466 893 894 895 896 897 898 899 467 900 if($dPin!="") 901 468 902 { 903 904 905 469 906 $data = array( 907 470 908 'cCountry' => $cCountry, 909 471 910 'cCity' => $cCity, 911 472 912 'cState' => $cState, 913 473 914 'cPin' => $cPin, 915 474 916 'dCountry' => $dCountry, 917 475 918 'dState' => $dState, 919 476 920 'dCity' => $dCity, 921 477 922 'dPin' => $dPin, 923 478 924 'Weight' => $Weight, 925 479 926 'Length' => $Length, 927 480 928 'Width' => $Width, 929 481 930 'Height' => $Height, 931 482 932 'Unit' => $Unit, 933 483 934 'Amount' => $Amount 935 484 936 ); 937 938 485 939 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 487 953 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 494 957 495 958 496 959 960 497 961 if($result) 962 498 963 { 964 499 965 966 500 967 $arrBFIShipping = explode(":",$result); 968 501 969 $ship_cost = floatval($arrBFIShipping[0]); 970 502 971 $_SESSION["bf_strBookingAmount"] = $ship_cost; 972 503 973 $carrier = $arrBFIShipping[1]; 974 504 975 $_SESSION["bf_strCarrier"] = $carrier; 976 505 977 $service = $arrBFIShipping[2]; 978 506 979 $_SESSION["bf_strService"] = $service; 980 507 981 $transit = $arrBFIShipping[4]; 982 508 983 984 509 985 $warranty = floatval($arrBFIShipping[5]); 986 510 987 988 511 989 $arrTransit = explode(" ",$transit); 990 512 991 $transitTime = $arrTransit[0]; 992 513 993 $_SESSION["bf_strTransitTime"] = $transitTime; 994 514 995 $_SESSION["bf_warranty"] = $warranty; 996 515 997 998 516 999 1000 517 1001 if(floatval($ship_cost)>0) 1002 518 1003 { 1004 519 1005 1006 520 1007 $_SESSION["bf_Weight"] = $Weight; 1008 521 1009 $_SESSION["bf_Length"] = $Length; 1010 522 1011 $_SESSION["bf_Width"] = $Width; 1012 523 1013 $_SESSION["bf_Height"] = $Height; 1014 524 1015 $_SESSION["bf_strDescription"] = $Desc; 1016 525 1017 $_SESSION["bf_Unit"] = $Unit; 1018 526 1019 1020 527 1021 $_SESSION["bf_booking"] = "1"; 1022 528 1023 $_SESSION["bf_strTotalBookingRate"] = $Amount; 1024 529 1025 1026 530 1027 1028 531 1029 $args= array( 1030 532 1031 'id' => $this->id, 1032 533 1033 'label' => $service." (Without Transit Warranty)", 1034 534 1035 'cost' => $ship_cost 1036 535 1037 ); 1038 536 1039 1040 537 1041 1042 538 1043 $this->add_rate( $args ); 1044 539 1045 1046 540 1047 1048 541 1049 if($warranty>0) 1050 542 1051 { 1052 543 1053 $ship_cost = $ship_cost+$warranty; 1054 544 1055 1056 545 1057 $args= array( 1058 546 1059 'id' => $this->id."1", 1060 547 1061 'label' => $service." (With Transit Warranty)", 1062 548 1063 'cost' => $ship_cost 1064 549 1065 ); 1066 550 1067 } 1068 551 1069 1070 552 1071 1072 553 1073 $this->add_rate( $args ); 1074 554 1075 } 1076 555 1077 } 1078 556 1079 } 1080 557 1081 1082 558 1083 } 559 1084 1085 1086 560 1087 } 561 1088 1089 1090 562 1091 } 563 1092 1093 1094 564 1095 function add_bf_shipping_method( $methods ) { 1096 565 1097 $methods[] = 'WC_BF_Shipping'; 1098 566 1099 return $methods; 1100 567 1101 } 568 1102 1103 1104 569 1105 function custom_woocommerce_billing_fields( $fields ) { 570 1106 571 1107 1108 1109 1110 572 1111 /*$fields['billing_city'] = array( 1112 573 1113 'label' => __('Town/City', 'woocommerce'), 1114 574 1115 'placeholder' => _x('Town/City', 'placeholder', 'woocommerce'), 1116 575 1117 'required' => true, 1118 576 1119 'class' => array('form-row-first', 'update_totals_on_change') 1120 577 1121 );*/ 1122 578 1123 1124 579 1125 $fields['billing_city']['class'] = array('form-row-first', 'update_totals_on_change'); 1126 580 1127 1128 581 1129 582 1130 1131 1132 583 1133 return $fields; 1134 584 1135 } 585 1136 1137 1138 586 1139 //add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' ); 587 1140 … … 589 1142 590 1143 1144 1145 1146 1147 1148 591 1149 function custom_woocommerce_shipping_fields( $fields ) { 592 1150 1151 1152 593 1153 /*$fields['shipping_city'] = array( 1154 594 1155 'label' => __('Town/City', 'woocommerce'), 1156 595 1157 'placeholder' => __('Town/City', 'placeholder', 'woocommerce'), 1158 596 1159 'required' => true, 1160 597 1161 'class' => array('form-row-first', 'update_totals_on_change') 1162 598 1163 );*/ 1164 599 1165 1166 600 1167 $fields['shipping_city']['class'] = array('form-row-first','update_totals_on_change'); 601 1168 1169 1170 602 1171 return $fields; 1172 603 1173 } 604 1174 1175 1176 605 1177 //add_filter( 'woocommerce_shipping_fields', 'custom_woocommerce_shipping_fields'); 606 1178 … … 609 1181 610 1182 1183 1184 1185 1186 1187 1188 611 1189 add_filter('woocommerce_shipping_methods', 'add_bf_shipping_method' );
Note: See TracChangeset
for help on using the changeset viewer.