/** * Cost of goods compatibility: Zero order item cost for bundled products that belong to statically priced bundles. * * @param double $cost * @param array $item * @param WC_Order $order * @return double */ public static function cost_of_goods_set_order_item_bundled_item_cost($cost, $item, $order) { if (!empty($item['bundled_by'])) { // Find bundle parent. $parent_item = WC_PB_Order::get_bundle_parent($item, $order); $per_product_pricing = !empty($parent_item) && isset($parent_item['per_product_pricing']) ? $parent_item['per_product_pricing'] : get_post_meta($parent_item['product_id'], '_per_product_pricing_active', true); if ($per_product_pricing === 'no') { return 0; } } elseif (!isset($item['bundled_by']) && isset($item['stamp'])) { $per_product_pricing = isset($item['per_product_pricing']) ? $item['per_product_pricing'] : get_post_meta($item['product_id'], '_per_product_pricing_active', true); if ($per_product_pricing === 'yes') { return 0; } } return $cost; }
/** * Used to link bundled order items with the composite container product. * * @param boolean $is_child * @param array $order_item * @param array $composite_item * @param WC_Order $order * @return boolean */ public static function bundled_order_item_is_child_of_composite($is_child, $order_item, $composite_item, $order) { if (!empty($order_item['bundled_by'])) { $parent = WC_PB_Order::get_bundle_parent($order_item, $order); if ($parent && isset($parent['composite_parent']) && $parent['composite_parent'] === $composite_item['composite_cart_key']) { return true; } } return $is_child; }
/** * Order API Modification #1: * * Restore virtual status and weights/dimensions of bundle containers/children depending on the "per-item pricing" and "per-item shipping" settings. * Virtual containers/children are assigned a zero weight and tiny dimensions in order to maintain the value of the associated item in shipments (for instance, when a bundle has a static price but is shipped per item). * * Restore bundle container price - equal to base price in "per-item pricing" mode. * * @param WC_Product $product * @param array $item * @param WC_Order $order * @return WC_Product */ public function get_product_from_item($product, $item, $order) { if (apply_filters('woocommerce_bundles_filter_product_from_item', false, $order)) { // Restore base price. if (!empty($product) && $product->product_type === 'bundle' && isset($item['bundled_items']) && isset($item['per_product_pricing']) && $item['per_product_pricing'] === 'yes') { $product->price = $product->get_base_price(); $product->regular_price = $product->get_base_regular_price(); $product->sale_price = $product->get_base_sale_price(); } // Modify shipping properties. if (!empty($product) && isset($item['stamp']) && isset($item['bundled_shipping'])) { if ($item['bundled_shipping'] === 'yes') { if (isset($item['bundled_weight'])) { $product->weight = $item['bundled_weight']; } } else { // Virtual container converted to non-virtual with zero weight and tiny dimensions if it has non-virtual bundled children. if (isset($item['bundled_items']) && isset($item['bundle_cart_key'])) { $bundle_key = $item['bundle_cart_key']; $non_virtual_child_exists = false; self::$override_order_items_filters = true; foreach ($order->get_items('line_item') as $child_item_id => $child_item) { if (isset($child_item['bundled_by']) && $child_item['bundled_by'] === $bundle_key && isset($child_item['bundled_shipping']) && $child_item['bundled_shipping'] === 'yes') { $non_virtual_child_exists = true; break; } } self::$override_order_items_filters = false; if ($non_virtual_child_exists) { $product->virtual = 'no'; } } $product->weight = 0; $product->length = $product->height = $product->width = 0.001; } } } return $product; }