Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active December 9, 2020 04:51
Show Gist options
  • Save xadapter/f330a6f529dfa9199a30ec2fa9fca3ef to your computer and use it in GitHub Desktop.
Save xadapter/f330a6f529dfa9199a30ec2fa9fca3ef to your computer and use it in GitHub Desktop.
/**
* Title : Snippet to add Fixed amount of weight to the order.
* Created at : 25 June 2018
* Updated at : 25 June 2018
* PlugiHive Plugins : https://www.pluginhive.com/product-category/woocommerce-plugin/
* Gist Link : https://gist.github.com/xadapter/f330a6f529dfa9199a30ec2fa9fca3ef
*/
add_filter( 'wf_customize_package_on_cart_and_checkout', function( $package ) {
$weight_to_be_added_to_order = 0; // Weight which needs to be added to the order.
$weight_to_be_added_to_each_product = $weight_to_be_added_to_order / count($package['contents']);
foreach( $package['contents'] as &$line_item ) {
$line_item['data']->set_weight( (float) $line_item['data']->get_weight() + $weight_to_be_added_to_each_product );
}
return $package;
});
@pettreegnat
Copy link

Is there any way to make this workable for multi-carrier shipping plugin? I would like to add 2 lbs to any order within a specific class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment