/** * Return the cart total weight * @param array $cart_items * @return number */ function calcul_cart_weight($cart_items) { $cart_weight = 0; if (!empty($cart_items)) { foreach ($cart_items as $id_item => $cart_item) { $id_item = wpshop_products::get_id_variation($id_item); if (get_post_type($id_item) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $product_data = get_post_meta($id_item, '_wpshop_product_metadata', true); if (!empty($product_data) && !empty($product_data['product_weight'])) { $cart_weight += $product_data['product_weight'] * $cart_item['item_qty']; } else { $parent_def = wpshop_products::get_parent_variation($id_item); if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['product_weight'])) { $cart_weight += $parent_def['parent_post_meta']['product_weight'] * $cart_item['item_qty']; } } } else { $product_data = get_post_meta($cart_item['item_id'], '_wpshop_product_metadata', true); if (!empty($product_data) && !empty($product_data['product_weight']) && !empty($cart_item['item_qty'])) { $cart_weight += $product_data['product_weight'] * $cart_item['item_qty']; } } } } return $cart_weight; }