Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This little snippet works when you have an array of packages and you want to get the weight of individual packages in WooCommerce. Usually used in the calculate shipping method. http://docs.woothemes.com/document/shipping-method-api/
<?php
foreach ( $package['contents'] as $item_id => $values ) {
// skip products that dont need shipping
if ( $values['data']->needs_shipping() ) {
// make sure a weight is set
if ( $values['data']->get_weight() ) {
$item_weight = $values['data']->get_weight();
// do something with the weight here
// ...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment