Description
Calculate shipping rates
Usage
OIK_Shipping::calculate_shipping( $package );Parameters
- $package
- ( array ) optional –
Returns
voidSource
File name: oik-weightcountry-shipping/oik-weightcountry-shipping.phpLines:
1 to 27 of 27
function calculate_shipping( $package = array() ) { $woocommerce = function_exists('WC') ? WC() : $GLOBALS['woocommerce']; $country_group = $this->get_countrygroup($package); $rates = $this->get_rates_by_countrygroup( $country_group ); //bw_trace2( $rates, "rates" ); $weight = $woocommerce->cart->cart_contents_weight; //bw_trace2( $weight, "cart contents weight" ); $final_rate = $this->pick_smallest_rate( $rates, $weight ); if ( $final_rate !== false && is_numeric( $final_rate )) { $taxable = ($this->tax_status == 'taxable') ? true : false; if ( $this->fee > 0 && $package['destination']['country'] ) { $final_rate += $this->fee; } $rate = array( 'id' => $this->id, 'label' => $this->countrygroup_title, 'cost' => $final_rate, 'taxes' => '', 'calc_tax' => 'per_order' ); $this->add_rate( $rate ); } else { add_filter( "woocommerce_cart_no_shipping_available_html", array( $this, 'no_shipping_available') ); } }View on GitHub View on Trac
Called by
Invoked by
Calls
1 to 3 of 3
- OIK_Shipping::get_countrygroup() – Retrieve the number of the country group for the country selected by the user on checkout
- OIK_Shipping::get_rates_by_countrygroup() – Retrieves all rates available for the selected country group
- OIK_Shipping::pick_smallest_rate() – Picks the right rate from available rates based on cart weight
