Last active
December 9, 2020 04:51
-
-
Save xadapter/f330a6f529dfa9199a30ec2fa9fca3ef to your computer and use it in GitHub Desktop.
Snippet to add Fixed amount of weight to the WooCommerce order. PluginHive plugins - https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/, https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
This file contains 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
/** | |
* 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; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.