Guest User

Untitled

a guest
Feb 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. add_filter( 'woocommerce_package_rates', 'add_shipping_option_base_fee', 10, 2 );
  2. function add_shipping_option_base_fee( $rates, $package ) {
  3.  
  4. foreach( $rates as $key => $rate ) {
  5. // reset defaults
  6. $highest_length = 0;
  7.  
  8. // Do not apply base fee if not the right option
  9. if( $rate->id !== 'betrs_shipping:1-1' ) continue;
  10.  
  11. // find highest priority class (BE Table Rate Shipping Only)
  12. foreach( $package['contents'] as $key => $values ) {
  13. $item_length = $values[ 'data' ]->get_length();
  14. if( $item_length > $highest_length ) {
  15. $highest_length = $item_length;
  16. }
  17. }
  18.  
  19. // Add $5 surcharge on orders with items larger than 21cm
  20. if( $highest_length > 21 ) {
  21. $rates[ $key ]->cost += 5.00;
  22. }
  23. }
  24.  
  25. return $rates;
  26. }
Add Comment
Please, Sign In to add comment