Skip to content

Instantly share code, notes, and snippets.

@michaeldaw
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save michaeldaw/298a90a8c7a7749f023f to your computer and use it in GitHub Desktop.

Select an option

Save michaeldaw/298a90a8c7a7749f023f to your computer and use it in GitHub Desktop.
Shipping stuff
add_filter( 'woocommerce_package_rates', 'determine_shipping_rate', 10, 2 );
function determine_shipping_rate( $rates, $package ) {
// Set weight variable
$cart_weight = 0;
// Calculate cart's total
foreach( WC()->cart->cart_contents as $key => $value)
$cart_weight += $value['data']->weight * $value['quantity'];
if( $cart_weight > 45.45) { // may have to convert to pounds if necessary
foreach($rates as $key => $value) {
$rates[$key] -> cost += 10;
}
}
if( WC()->customer->shipping_state != "AB"){
foreach($rates as $key => $value) {
$rates[$key] -> cost += 0.25 * $cart_weight;
}
}
return $rates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment