Want to add custom shipping charge in woocommerce? Better to make custom plugin for shipping charge where you can use hook. First extend ‘WC_Your_Shipping_Method’ class in your custom plugin and make function like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | public function calculate_shipping( $package ) { session_start(); global $woocommerce; $carttotal = $woocommerce->cart->subtotal; $country = $_POST['s_country']; //$package['destination']['country']; if($country == 'AU') { if($carttotal > 100){ $cost = 5; }else{ $cost = 10;//10.00; } } else { if($carttotal < 500){ $cost = 60;//60.00; }else if($carttotal >= 500 && $carttotal <= 1000){ $cost = 50;//50.00; }else if($carttotal > 1000){ $cost = 0; } } $rate = array( 'id' => $this->id, 'label' => 'Shipping', 'cost' => $cost, 'calc_tax' => 'per_order' ); // Register the rate $this->add_rate( $rate ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.