I want to add shipping cost using code in woocommerce. here are my recommendations.
If my shipping country is Australia, the shipping cost is different and outside of Australia also different. now if my delivery country is Australia and
1. if order value is < 100, then shipping charge is $100 2. if order value is > 100, then shipping charge is $0.
If my delivery country is outside of Australia and
1. if order value is < 500, then shipping charge is $60 2. if order value is > 500 and < 1000, then shipping charge is $50 3. if order value is > 1000, then shipping charge is $0
So, how can I add custom shipping cost in accordance with my above requirements when the user changes the country of delivery from the checkout page. I tried the code below, but it only works on the order value, how can I add the delivery country to the code below in the user plugin.
class WC_Your_Shipping_Method extends WC_Shipping_Method { public function calculate_shipping( $package ) { global $woocommerce; if($woocommerce->cart->subtotal > 5000) { $cost = 30; }else{ $cost = 3000; } } $rate = array( 'id' => $this->id, 'label' => $this->title, 'cost' => $cost, 'calc_tax' => 'per_order' );
}
php wordpress woocommerce
Ketan lathiya
source share