Skip to content

Instantly share code, notes, and snippets.

@bolderelements
Created August 28, 2019 02:22
Show Gist options
  • Save bolderelements/5c8571203f0e50c5777ae4af8c71e28e to your computer and use it in GitHub Desktop.
Save bolderelements/5c8571203f0e50c5777ae4af8c71e28e to your computer and use it in GitHub Desktop.
Modify the Order Length for Table Rate Shipping Settings
/*
* 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