Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Created March 29, 2014 18:44
Show Gist options
  • Save BFTrick/9860505 to your computer and use it in GitHub Desktop.
Save BFTrick/9860505 to your computer and use it in GitHub Desktop.
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