Created
August 28, 2019 02:22
-
-
Save bolderelements/5c8571203f0e50c5777ae4af8c71e28e to your computer and use it in GitHub Desktop.
Modify the Order Length for Table Rate Shipping Settings
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
/* | |
* Recalculate the order's length to ignore multiple quantities. | |
* | |
* Requires Table Rate Shipping 4.2+ | |
*/ | |
function betrs_modify_calculated_length( $calculated_totals, $items ){ | |
// ensure there are items in the cart | |
if( is_array( $items ) ) { | |
$length = 0; | |
// find length for items | |
foreach( $items as $key => $item ) { | |
$length += floatval( $item['data']->get_length() ); | |
} | |
// change calculated length | |
$calculated_totals['length'] = $length; | |
} | |
return $calculated_totals; | |
} | |
add_filter( 'betrs_calculated_totals-per_order', 'betrs_modify_calculated_length', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment