src/WooCommerce/Invoice/CreatorPluginSupport.php
protected function supportBundleProducts($invoice, BaseSource $invoiceSource, /** @noinspection PhpUnusedParameterInspection */ Result $localResult)
    {
        /** @var \WC_Abstract_Order $shopSource */
        $shopSource = $invoiceSource->getSource();
        /** @var WC_Order_Item_Product[] $items */
        $items = $shopSource->get_items(apply_filters('woocommerce_admin_order_item_types', 'line_item'));
        foreach ($items as $item) {
            $bundleId = $item->get_meta('_bundle_cart_key');
            $bundledBy = $item->get_meta('_bundled_by');
            if (!empty($bundleId) || !empty($bundledBy)) {
                $line = &$this->getLineByMetaId($invoice[Tag::Customer][Tag::Invoice][Tag::Line], $item->get_id());
                if ($line !== null) {
                    // Add bundle meta data.
                    if ( !empty($bundleId)) {
                        // Bundle or bundled product.
                        $line[Meta::BundleId] = $bundleId;
                    }
                    if ( !empty($bundledBy)) {
                        // Bundled products only.
                        $line[Meta::BundleParentId] = $bundledBy;
                        $line[Meta::BundleVisible] = $item->get_meta('bundled_item_hidden') !== 'yes';
                    }
                }
            }
        }

        $invoice[Tag::Customer][Tag::Invoice][Tag::Line] = $this->groupBundles($invoice[Tag::Customer][Tag::Invoice][Tag::Line]);

        return $invoice;
    }
protected function supportBundleProducts($invoice, BaseSource $invoiceSource, /** @noinspection PhpUnusedParameterInspection */ Result $localResult)
    {
        /** @var \WC_Abstract_Order $shopSource */
        $shopSource = $invoiceSource->getSource();
        /** @var WC_Order_Item_Product[] $items */
        $items = $shopSource->get_items(apply_filters('woocommerce_admin_order_item_types', 'line_item'));
        foreach ($items as $item) {
            $bundleId = $item->get_meta('_bundle_cart_key');
            $bundledBy = $item->get_meta('_bundled_by');
            if (!empty($bundleId) || !empty($bundledBy)) {
                $line = &$this->getLineByMetaId($invoice[Tag::Customer][Tag::Invoice][Tag::Line], $item->get_id());
                if ($line !== null) {
                    // Add bundle meta data.
                    if ( !empty($bundleId)) {
                        // Bundle or bundled product.
                        $line[Meta::BundleId] = $bundleId;
                    }
                    if ( !empty($bundledBy)) {
                        // Bundled products only.
                        $line[Meta::BundleParentId] = $bundledBy;
                        $line[Meta::BundleVisible] = $item->get_meta('bundled_item_hidden') !== 'yes';
                    }
                }
            }
        }

        $invoice[Tag::Customer][Tag::Invoice][Tag::Line] = $this->groupBundles($invoice[Tag::Customer][Tag::Invoice][Tag::Line]);

        return $invoice;
    }
protected function supportBundleProducts ( $ invoice , BaseSource $ invoiceSource , /** @noinspection PhpUnusedParameterInspection */ Result $ localResult ) { /** @var \WC_Abstract_Order $shopSource */ $ shopSource = $ invoiceSource -> getSource ( ) ; /** @var WC_Order_Item_Product[] $items */ $ items = $ shopSource -> get_items ( apply_filters ( 'woocommerce_admin_order_item_types' , 'line_item' ) ) ; foreach ( $ items as $ item ) { $ bundleId = $ item -> get_meta ( '_bundle_cart_key' ) ; $ bundledBy = $ item -> get_meta ( '_bundled_by' ) ; if ( ! empty ( $ bundleId ) || ! empty ( $ bundledBy ) ) { $ line = & $ this -> getLineByMetaId ( $ invoice [ Tag :: Customer ] [ Tag :: Invoice ] [ Tag :: Line ] , $ item -> get_id ( ) ) ; if ( $ line !== null ) { // Add bundle meta data. if ( ! empty ( $ bundleId ) ) { // Bundle or bundled product. $ line [ Meta :: BundleId ] = $ bundleId ; } if ( ! empty ( $ bundledBy ) ) { // Bundled products only. $ line [ Meta :: BundleParentId ] = $ bundledBy ; $ line [ Meta :: BundleVisible ] = $ item -> get_meta ( 'bundled_item_hidden' ) !== 'yes' ; } } } } $ invoice [ Tag :: Customer ] [ Tag :: Invoice ] [ Tag :: Line ] = $ this -> groupBundles ( $ invoice [ Tag :: Customer ] [ Tag :: Invoice ] [ Tag :: Line ] ) ; return $ invoice ; }
Supports the "WooCommerce Bundle Products" plugin.

This method supports the woocommerce-product-bundles extension that
stores the bundle products as separate item lines below the bundle line
and uses the meta data described below to link them to each other.

This method hierarchically groups bundled products into the bundle
product and can do so multi-level.

Meta data on bundle lines:
- bundle_cart_key (hash) unique identifier.
- bundled_items (hash[]) refers to the bundle_cart_key of the bundled
products.

Meta data on bundled items:
- bundled_by (hash) refers to bundle_cart_key of the bundle line.
- bundle_cart_key (hash) unique identifier.
- bundled_item_hidden: 'yes'|'no' or absent (= 'no').

1) In a 1st pass, we first add bundle meta data to each invoice line that
represents a bundle or bundled item.
2) In a 2nd pass, we group the bundled items as children into the parent
line.

@param array|null $invoice
@param \Siel\Acumulus\Invoice\Source $invoiceSource
@param \Siel\Acumulus\Invoice\Result $localResult

@return array|null
Supports the WooCommerce Bundle Products plugin .