Created
March 29, 2014 18:44
-
-
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/
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
<?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