Cray
Cray

Reputation: 5493

WooCommerce: Get data from each bundled product

I want to export my orders with some additional information per product. Therefore I wrote a function to get every item from an order in a single line (in my case as CSV).

I'm using the following code to get extra information from the product. It works well but if I have a bundle in the order, the product informations are wrong. They show every item with the same vendor/user information. But inside the bundle are products from different vendors/users.

Is there an other way to get these informations from bundles?

function sv_wc_csv_export_modify_row_data_example( $order_data, $order, $csv_generator ) {

        // Loop through order line items
        foreach( $order->get_items() as $item ){

            $item_vendor_id = get_post_field( 'post_author', $item->get_product_id() );

            $custom_data = array(

                // Commissin/Fee
                'item_commission'           => '',
                'item_fee'                  => '',

                // User/Vendor
                'item_vendor_id'            => $item_vendor_id,
                'vendor_username'           => get_the_author_meta( 'username', $item_vendor_id ),
                'vendor_user_email'         => get_the_author_meta( 'user_email', $item_vendor_id ),

                // Address
                'vendor_company'            => get_the_author_meta( '_wcv_custom_settings_company_name', $item_vendor_id ),
                'vendor_street'             => get_the_author_meta( '_wcv_store_address1', $item_vendor_id ),
                'vendor_housenumber'        => get_the_author_meta( '_wcv_store_address2', $item_vendor_id ),
                'vendor_zip'                => get_the_author_meta( '_wcv_store_postcode', $item_vendor_id ),
                'vendor_city'               => get_the_author_meta( '_wcv_store_city', $item_vendor_id ),
                'vendor_country'            => get_the_author_meta( '_wcv_store_country', $item_vendor_id ),

                );
        }


        return sv_wc_csv_export_add_custom_order_data( $order_data, $custom_data, $csv_generator );
}
add_filter( 'wc_customer_order_export_csv_order_row', 'sv_wc_csv_export_modify_row_data_example', 10, 3 );

Upvotes: 0

Views: 1688

Answers (0)

Related Questions