Last active
August 29, 2015 14:27
-
-
Save michaeldaw/298a90a8c7a7749f023f to your computer and use it in GitHub Desktop.
Shipping stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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