예제 #1
0
function woo_ce_extend_order_items_individual( $order, $order_item ) {

	global $export;

	// Product Add-ons - http://www.woothemes.com/
	if( $product_addons = woo_ce_get_product_addons() ) {
		foreach( $product_addons as $product_addon ) {
			if( isset( $order_item->product_addons[$product_addon->post_name] ) )
				$order->{'order_items_product_addon_' . $product_addon->post_name} = $order_item->product_addons[$product_addon->post_name];
		}
	}

	// Gravity Forms - http://woothemes.com/woocommerce
	if( $gf_fields = woo_ce_get_gravity_form_fields() ) {
		if( $order->order_items ) {
			$order->order_items_gf_form_id = $order_item->gf_form_id;
			$order->order_items_gf_form_label = $order_item->gf_form_label;
			$meta_type = 'order_item';
			foreach( $gf_fields as $gf_field ) {
				// Check that we only fill export fields for forms that are actually filled
				if( $gf_field['formId'] == $order_item->gf_form_id )
					$order->{sprintf( 'order_items_gf_%d_%s', $gf_field['formId'], $gf_field['id'] )} = get_metadata( $meta_type, $order_item->id, $gf_field['label'], true );
			}
			unset( $gf_fields, $gf_field );
		}
	}

	// WooCommerce Checkout Add-Ons - http://www.skyverge.com/product/woocommerce-checkout-add-ons/
	if( function_exists( 'init_woocommerce_checkout_add_ons' ) ) {
		$order->order_items_checkout_addon_id = $order_item->checkout_addon_id;
		$order->order_items_checkout_addon_label = $order_item->checkout_addon_label;
		$order->order_items_checkout_addon_value = $order_item->checkout_addon_value;
	}

	// WooCommerce Brands Addon - http://woothemes.com/woocommerce/
	// WooCommerce Brands - http://proword.net/Woocommerce_Brands/
	if( class_exists( 'WC_Brands' ) || class_exists( 'woo_brands' ) || taxonomy_exists( apply_filters( 'woo_ce_brand_term_taxonomy', 'product_brand' ) ) )
		$order->order_items_brand = $order_item->brand;

	// Product Vendors - http://www.woothemes.com/products/product-vendors/
	if( class_exists( 'WooCommerce_Product_Vendors' ) )
		$order->order_items_vendor = $order_item->vendor;

	// Cost of Goods - http://www.skyverge.com/product/woocommerce-cost-of-goods-tracking/
	if( class_exists( 'WC_COG' ) ) {
		$order->order_items_cost_of_goods = $order_item->cost_of_goods;
		$order->order_items_total_cost_of_goods = $order_item->total_cost_of_goods;
	}

	// WooCommerce MSRP Pricing - http://woothemes.com/woocommerce/
	if( function_exists( 'woocommerce_msrp_activate' ) )
		$order->order_items_msrp = $order_item->msrp;

	// Local Pickup Plus - http://www.woothemes.com/products/local-pickup-plus/
	if( class_exists( 'WC_Local_Pickup_Plus' ) ) {
		$meta_type = 'order_item';
		$pickup_location = get_metadata( $meta_type, $order_item->id, 'Pickup Location', true );
		if( !empty( $pickup_location ) )
			$order->order_items_pickup_location = get_metadata( $meta_type, $order_item->id, 'Pickup Location', true );
		unset( $pickup_location );
	}

	// WooCommerce Bookings - http://www.woothemes.com/products/woocommerce-bookings/
	if( class_exists( 'WC_Bookings' ) ) {
		$booking_id = woo_ce_get_order_assoc_booking_id( $order->id );
		if( !empty( $booking_id ) ) {
			$order->order_items_booking_id = $booking_id;
			$booking_start_date = get_post_meta( $booking_id, '_booking_start', true );
			if( !empty( $booking_start_date ) )
				$order->order_items_booking_start_date = woo_ce_format_date( date( 'Y-m-d', strtotime( $booking_start_date ) ) );
			unset( $booking_start_date );
			$booking_end_date = get_post_meta( $booking_id, '_booking_end', true );
			if( !empty( $booking_end_date ) )
				$order->order_items_booking_end_date = woo_ce_format_date( date( 'Y-m-d', strtotime( $booking_end_date ) ) );
			unset( $booking_end_date );
		}
		unset( $booking_id );
		$meta_type = 'order_item';
		$booking_date = get_metadata( $meta_type, $order_item->id, 'Booking Date', true );
		if( !empty( $booking_date ) )
			$order->order_items_booking_date = get_metadata( $meta_type, $order_item->id, 'Booking Date', true );
		unset( $booking_date );
		$booking_type = get_metadata( $meta_type, $order_item->id, 'Booking Type', true );
		if( !empty( $booking_type ) )
			$order->order_items_booking_type = get_metadata( $meta_type, $order_item->id, 'Booking Type', true );
		unset( $booking_type );
	}

	// WooCommerce TM Extra Product Options - http://codecanyon.net/item/woocommerce-extra-product-options/7908619
	if( class_exists( 'TM_Extra_Product_Options' ) ) {
		if( $tm_fields = woo_ce_get_extra_product_option_fields() ) {
			foreach( $tm_fields as $tm_field )
				$order->{sprintf( 'order_items_tm_%s', sanitize_key( $tm_field['name'] ) )} = $order_item->{sprintf( 'tm_%s', sanitize_key( $tm_field['name'] ) )};
		}
		unset( $tm_fields, $tm_field );
	}

	// Attributes
	if( $attributes = woo_ce_get_product_attributes() ) {
		foreach( $attributes as $attribute ) {
			if( isset( $order_item->{'attribute_' . sanitize_key( $attribute->attribute_name )} ) )
				$order->{'order_items_attribute_' . sanitize_key( $attribute->attribute_name )} = $order_item->{'attribute_' . sanitize_key( $attribute->attribute_name )};
		}
		unset( $attributes, $attribute );
	}

	// WooCommerce Ship to Multiple Addresses - http://woothemes.com/woocommerce
	if( class_exists( 'WC_Ship_Multiple' ) ) {
		$shipping_packages = get_post_meta( $order->ID, '_wcms_packages', true );
		if( !empty( $shipping_packages ) ) {

			// Override the Shipping address
			$order->shipping_first_name = '';
			$order->shipping_last_name = '';
			if( empty( $order->shipping_first_name ) && empty( $order->shipping_first_name ) )
				$order->shipping_full_name = '';
			else
				$order->shipping_full_name = '';
			$order->shipping_company = '';
			$order->shipping_address = '';
			$order->shipping_address_1 = '';
			$order->shipping_address_2 = '';
			$order->shipping_city = '';
			$order->shipping_postcode = '';
			$order->shipping_state = '';
			$order->shipping_country = '';
			$order->shipping_state_full = '';
			$order->shipping_country_full = '';

			// Override the shipping method

			foreach( $shipping_packages as $shipping_package ) {
				$contents = $shipping_package['contents'];
				if( !empty( $contents ) ) {
					foreach( $contents as $content ) {
						if( $content['product_id'] == $order_item->product_id ) {
							$order->shipping_first_name = $shipping_package['full_address']['first_name'];
							$order->shipping_last_name = $shipping_package['full_address']['last_name'];
							if( empty( $order->shipping_first_name ) && empty( $order->shipping_last_name ) )
								$order->shipping_full_name = '';
							else
								$order->shipping_full_name = $order->shipping_first_name . ' ' . $order->shipping_last_name;
							$order->shipping_company = $shipping_package['full_address']['company'];
							$order->shipping_address = '';
							$order->shipping_address_1 = $shipping_package['full_address']['address_1'];
							$order->shipping_address_2 = $shipping_package['full_address']['address_2'];
							if( !empty( $order->billing_address_2 ) )
								$order->shipping_address = sprintf( apply_filters( 'woo_ce_get_order_data_shipping_address', '%s %s' ), $order->shipping_address_1, $order->shipping_address_2 );
							else
								$order->shipping_address = $order->shipping_address_1;
							$order->shipping_city = $shipping_package['full_address']['city'];
							$order->shipping_postcode = $shipping_package['full_address']['postcode'];
							$order->shipping_state = $shipping_package['full_address']['state'];
							$order->shipping_country = $shipping_package['full_address']['country'];
							$order->shipping_state_full = woo_ce_expand_state_name( $order->shipping_country, $order->shipping_state );
							$order->shipping_country_full = woo_ce_expand_country_name( $order->shipping_country );
							break;
							break;
						}
					}
				}
				unset( $contents );
			}

		}
		unset( $shipping_packages );
	}

	// Custom Order Items fields
	$custom_order_items = woo_ce_get_option( 'custom_order_items', '' );
	if( !empty( $custom_order_items ) ) {
		foreach( $custom_order_items as $custom_order_item ) {
			if( !empty( $custom_order_item ) )
				$order->{'order_items_' . $custom_order_item} = $order_item->{$custom_order_item};
		}
	}
	unset( $custom_order_items, $custom_order_item );

	// Custom Product fields
	$custom_products = woo_ce_get_option( 'custom_products', '' );
	if( !empty( $custom_products ) ) {
		foreach( $custom_products as $custom_product ) {
			if( !empty( $custom_product ) )
				$order->{'order_items_' . $custom_product} = $order_item->{$custom_product};
		}
	}
	unset( $custom_products, $custom_product );

	return $order;

}
예제 #2
0
function woo_cd_get_orders($export_type = 'orders', $args = array())
{
    global $export;
    $limit_volume = -1;
    $offset = 0;
    if ($args) {
        $user_roles = $args['order_user_roles'];
        $limit_volume = $args['limit_volume'];
        $offset = $args['offset'];
        $orderby = $args['order_orderby'];
        $order = $args['order_order'];
        switch ($args['order_dates_filter']) {
            case 'current_month':
                $order_dates_from = date('d-m-Y', mktime(0, 0, 0, date('m'), 1, date('Y')));
                $order_dates_to = date('d-m-Y', mktime(0, 0, 0, date('m') + 1, 0, date('Y')));
                break;
            case 'last_month':
                $order_dates_from = date('d-m-Y', mktime(0, 0, 0, date('m') - 1, 1, date('Y')));
                $order_dates_to = date('d-m-Y', mktime(0, 0, 0, date('m'), 0, date('Y')));
                break;
            case 'last_quarter':
                break;
            case 'manual':
                $order_dates_from = $args['order_dates_from'];
                $order_dates_to = $args['order_dates_to'];
                break;
            default:
                $order_dates_from = false;
                $order_dates_to = false;
                break;
        }
        if ($order_dates_from && $order_dates_to) {
            $order_dates_from = strtotime($order_dates_from);
            $order_dates_to = explode('-', $order_dates_to);
            $order_dates_to = strtotime(date('d-m-Y', mktime(0, 0, 0, $order_dates_to[1], $order_dates_to[0] + 1, $order_dates_to[2])));
        }
        $order_status = $args['order_status'];
        $user_id = $args['order_customer'];
        $order_items = $args['order_items'];
    }
    $post_type = 'shop_order';
    $args = array('post_type' => $post_type, 'orderby' => $orderby, 'order' => $order, 'numberposts' => $limit_volume, 'offset' => $offset, 'post_status' => woo_ce_post_statuses(), 'cache_results' => false, 'no_found_rows' => false);
    if (!empty($order_status)) {
        $term_taxonomy = 'shop_order_status';
        $args['tax_query'] = array(array('taxonomy' => $term_taxonomy, 'field' => 'slug', 'terms' => $order_status));
    }
    if (!empty($user_id)) {
        if ($user = get_userdata($user_id)) {
            $args['meta_key'] = '_billing_email';
            $args['meta_value'] = $user->user_email;
        }
    }
    $export->total_rows = 0;
    if ($orders = get_posts($args)) {
        $export->total_rows = count($orders);
        foreach ($orders as $key => $order) {
            // $order = woo_cd_get_order_data( $order );
            // Filter Order dates by dropping those outside the date range
            if ($order_dates_from && $order_dates_to) {
                if (strtotime($order->post_date) > $order_dates_from && strtotime($order->post_date) < $order_dates_to) {
                    // Do nothing
                } else {
                    unset($orders[$key]);
                    continue;
                }
            }
            $orders[$key]->user_id = get_post_meta($order->ID, '_customer_user', true);
            // Filter Orders by User Roles
            if ($user_roles) {
                $user_ids = array();
                $size = count($export->args['order_user_roles']);
                for ($i = 0; $i < $size; $i++) {
                    $args = array('role' => $export->args['order_user_roles'][$i], 'fields' => 'ID');
                    $user_id = get_users($args);
                    $user_ids = array_merge($user_ids, $user_id);
                }
                if (!in_array($orders[$key]->user_id, $user_ids)) {
                    unset($orders[$key]);
                    continue;
                }
            }
            $orders[$key]->purchase_total = get_post_meta($order->ID, '_order_total', true);
            $orders[$key]->payment_status = woo_cd_get_order_status($order->ID);
            if ($orders[$key]->user_id == 0) {
                $orders[$key]->user_id = '';
            }
            $orders[$key]->user_name = woo_cd_get_username($orders[$key]->user_id);
            $orders[$key]->user_role = woo_ce_format_user_role_label(woo_cd_get_user_role($orders[$key]->user_id));
            $orders[$key]->billing_first_name = get_post_meta($order->ID, '_billing_first_name', true);
            $orders[$key]->billing_last_name = get_post_meta($order->ID, '_billing_last_name', true);
            if (empty($orders[$key]->billing_first_name) && empty($orders[$key]->billing_first_name)) {
                $orders[$key]->billing_full_name = '';
            } else {
                $orders[$key]->billing_full_name = $orders[$key]->billing_first_name . ' ' . $orders[$key]->billing_last_name;
            }
            $orders[$key]->billing_company = get_post_meta($order->ID, '_billing_company', true);
            $orders[$key]->billing_address = get_post_meta($order->ID, '_billing_address_1', true);
            $orders[$key]->billing_address_alt = get_post_meta($order->ID, '_billing_address_2', true);
            if ($orders[$key]->billing_address_alt) {
                $orders[$key]->billing_address .= ' ' . $orders[$key]->billing_address_alt;
            }
            $orders[$key]->billing_city = get_post_meta($order->ID, '_billing_city', true);
            $orders[$key]->billing_postcode = get_post_meta($order->ID, '_billing_postcode', true);
            $orders[$key]->billing_state = get_post_meta($order->ID, '_billing_state', true);
            $orders[$key]->billing_country = get_post_meta($order->ID, '_billing_country', true);
            $orders[$key]->billing_state_full = woo_ce_expand_state_name($orders[$key]->billing_country, $orders[$key]->billing_state);
            $orders[$key]->billing_country_full = woo_ce_expand_country_name($orders[$key]->billing_country);
            $orders[$key]->billing_phone = get_post_meta($order->ID, '_billing_phone', true);
            $orders[$key]->billing_email = get_post_meta($order->ID, '_billing_email', true);
            $orders[$key]->shipping_first_name = get_post_meta($order->ID, '_shipping_first_name', true);
            $orders[$key]->shipping_last_name = get_post_meta($order->ID, '_shipping_last_name', true);
            if (empty($orders[$key]->shipping_first_name) && empty($orders[$key]->shipping_first_name)) {
                $orders[$key]->shipping_full_name = '';
            } else {
                $orders[$key]->shipping_full_name = $orders[$key]->shipping_first_name . ' ' . $orders[$key]->shipping_last_name;
            }
            $orders[$key]->shipping_company = get_post_meta($order->ID, '_shipping_company', true);
            $orders[$key]->shipping_address = get_post_meta($order->ID, '_shipping_address_1', true);
            $orders[$key]->shipping_address_alt = get_post_meta($order->ID, '_shipping_address_2', true);
            if ($orders[$key]->shipping_address_alt) {
                $orders[$key]->shipping_address .= ' ' . $orders[$key]->shipping_address_alt;
            }
            $orders[$key]->shipping_city = get_post_meta($order->ID, '_shipping_city', true);
            $orders[$key]->shipping_postcode = get_post_meta($order->ID, '_shipping_postcode', true);
            $orders[$key]->shipping_state = get_post_meta($order->ID, '_shipping_state', true);
            $orders[$key]->shipping_country = get_post_meta($order->ID, '_shipping_country', true);
            $orders[$key]->shipping_state_full = woo_ce_expand_state_name($orders[$key]->shipping_country, $orders[$key]->shipping_state);
            $orders[$key]->shipping_country_full = woo_ce_expand_country_name($orders[$key]->shipping_country);
            $orders[$key]->shipping_phone = get_post_meta($order->ID, '_shipping_phone', true);
            if ($export_type == 'orders') {
                $orders[$key]->purchase_id = $order->ID;
                $orders[$key]->order_discount = get_post_meta($order->ID, '_order_discount', true);
                $orders[$key]->order_sales_tax = get_post_meta($order->ID, '_order_tax', true);
                $orders[$key]->order_shipping_tax = get_post_meta($order->ID, '_order_shipping_tax', true);
                $orders[$key]->order_excl_tax = $orders[$key]->purchase_total - ($orders[$key]->order_sales_tax - $orders[$key]->order_shipping_tax);
                $orders[$key]->payment_status = woo_cd_format_order_status($orders[$key]->payment_status);
                $orders[$key]->payment_gateway_id = get_post_meta($order->ID, '_payment_method', true);
                $orders[$key]->payment_gateway = woo_cd_format_order_payment_gateway($orders[$key]->payment_gateway_id);
                $orders[$key]->shipping_method_id = get_post_meta($order->ID, '_shipping_method', true);
                $orders[$key]->shipping_method = woo_cd_format_shipping_method($orders[$key]->shipping_method_id);
                $orders[$key]->shipping_cost = get_post_meta($order->ID, '_order_shipping', true);
                $orders[$key]->order_key = get_post_meta($order->ID, '_order_key', true);
                $orders[$key]->purchase_date = woo_ce_format_date($order->post_date);
                $orders[$key]->purchase_time = mysql2date('H:i:s', $order->post_date);
                $orders[$key]->customer_note = $order->post_excerpt;
                $orders[$key]->ip_address = get_post_meta($order->ID, '_customer_ip_address', true);
                $orders[$key]->browser_agent = get_post_meta($order->ID, '_customer_user_agent', true);
                $orders[$key]->order_notes = '';
                if ($order_notes = woo_cd_get_order_assoc_notes($order->ID)) {
                    foreach ($order_notes as $order_note) {
                        $orders[$key]->order_notes .= $order_note->comment_content . $export->category_separator;
                    }
                    $orders[$key]->order_notes = substr($orders[$key]->order_notes, 0, -1);
                    unset($order_notes);
                }
                $orders[$key]->order_items_size = 0;
                if ($orders[$key]->order_items = woo_cd_get_order_items($order->ID)) {
                    $orders[$key]->order_items_size = count($orders[$key]->order_items);
                    if ($order_items == 'combined') {
                        $orders[$key]->order_items_product_id = '';
                        $orders[$key]->order_items_variation_id = '';
                        $orders[$key]->order_items_sku = '';
                        $orders[$key]->order_items_name = '';
                        $orders[$key]->order_items_variation = '';
                        $orders[$key]->order_items_tax_class = '';
                        $orders[$key]->order_items_quantity = '';
                        $orders[$key]->order_items_total = '';
                        $orders[$key]->order_items_subtotal = '';
                        $orders[$key]->order_items_tax = '';
                        $orders[$key]->order_items_tax_subtotal = '';
                        $orders[$key]->order_items_type = '';
                        $orders[$key]->order_items_category = '';
                        $orders[$key]->order_items_tag = '';
                        foreach ($orders[$key]->order_items as $order_item) {
                            if (empty($order_item->sku)) {
                                $order_item->sku = '-';
                            }
                            $orders[$key]->order_items_product_id .= $order_item->product_id . $export->category_separator;
                            $orders[$key]->order_items_variation_id .= $order_item->variation_id . $export->category_separator;
                            $orders[$key]->order_items_sku .= $order_item->sku . $export->category_separator;
                            $orders[$key]->order_items_name .= $order_item->name . $export->category_separator;
                            $orders[$key]->order_items_variation .= $order_item->variation . $export->category_separator;
                            $orders[$key]->order_items_tax_class .= $order_item->tax_class . $export->category_separator;
                            if (empty($order_item->quantity) && '0' != $order_item->quantity) {
                                $order_item->quantity = '-';
                            }
                            $orders[$key]->order_items_quantity .= $order_item->quantity . $export->category_separator;
                            $orders[$key]->order_items_total .= $order_item->total . $export->category_separator;
                            $orders[$key]->order_items_subtotal .= $order_item->subtotal . $export->category_separator;
                            $orders[$key]->order_items_tax .= $order_item->tax . $export->category_separator;
                            $orders[$key]->order_items_tax_subtotal .= $order_item->tax_subtotal . $export->category_separator;
                            $orders[$key]->order_items_type .= $order_item->type . $export->category_separator;
                            $orders[$key]->order_items_category .= $order_item->category . $export->category_separator;
                            $orders[$key]->order_items_tag .= $order_item->tag . $export->category_separator;
                        }
                        $orders[$key]->order_items_product_id = substr($orders[$key]->order_items_product_id, 0, -1);
                        $orders[$key]->order_items_variation_id = substr($orders[$key]->order_items_variation_id, 0, -1);
                        $orders[$key]->order_items_sku = substr($orders[$key]->order_items_sku, 0, -1);
                        $orders[$key]->order_items_name = substr($orders[$key]->order_items_name, 0, -1);
                        $orders[$key]->order_items_variation = substr($orders[$key]->order_items_variation, 0, -1);
                        $orders[$key]->order_items_tax_class = substr($orders[$key]->order_items_tax_class, 0, -1);
                        $orders[$key]->order_items_quantity = substr($orders[$key]->order_items_quantity, 0, -1);
                        $orders[$key]->order_items_total = substr($orders[$key]->order_items_total, 0, -1);
                        $orders[$key]->order_items_subtotal = substr($orders[$key]->order_items_subtotal, 0, -1);
                        $orders[$key]->order_items_type = substr($orders[$key]->order_items_type, 0, -1);
                        $orders[$key]->order_items_category = substr($orders[$key]->order_items_category, 0, -1);
                        $orders[$key]->order_items_tag = substr($orders[$key]->order_items_tag, 0, -1);
                        $orders[$key] = apply_filters('woo_cd_order_items_combined', $orders[$key]);
                    } else {
                        if ($order_items == 'unique') {
                            $i = 1;
                            foreach ($orders[$key]->order_items as $order_item) {
                                if (empty($order_item->sku)) {
                                    $order_item->sku = '-';
                                }
                                $orders[$key]->{sprintf('order_item_%d_product_id', $i)} = $order_item->product_id;
                                $orders[$key]->{sprintf('order_item_%d_variation_id', $i)} = $order_item->variation_id;
                                $orders[$key]->{sprintf('order_item_%d_sku', $i)} = $order_item->sku;
                                $orders[$key]->{sprintf('order_item_%d_name', $i)} = $order_item->name;
                                $orders[$key]->{sprintf('order_item_%d_variation', $i)} = $order_item->variation;
                                $orders[$key]->{sprintf('order_item_%d_tax_class', $i)} = $order_item->tax_class;
                                if (empty($order_item->quantity) && '0' != $order_item->quantity) {
                                    $order_item->quantity = '-';
                                }
                                $orders[$key]->{sprintf('order_item_%d_quantity', $i)} = $order_item->quantity;
                                $orders[$key]->{sprintf('order_item_%d_total', $i)} = $order_item->total;
                                $orders[$key]->{sprintf('order_item_%d_subtotal', $i)} = $order_item->subtotal;
                                $orders[$key]->{sprintf('order_item_%d_tax', $i)} = $order_item->tax;
                                $orders[$key]->{sprintf('order_item_%d_tax_subtotal', $i)} = $order_item->tax_subtotal;
                                $orders[$key]->{sprintf('order_item_%d_type', $i)} = $order_item->type;
                                $orders[$key]->{sprintf('order_item_%d_category', $i)} = $order_item->category;
                                $orders[$key]->{sprintf('order_item_%d_tag', $i)} = $order_item->tag;
                                $orders[$key] = apply_filters('woo_cd_order_items_unique', $orders[$key], $i, $order_item);
                                $i++;
                            }
                        }
                    }
                    // Custom
                    $custom_order_items = woo_ce_get_option('custom_order_items', '');
                    if (!empty($custom_order_items)) {
                        foreach ($custom_order_items as $custom_order_item) {
                            if (!empty($custom_order_item)) {
                                $orders[$key]->{$custom_order_item} = get_post_meta($order->ID, $custom_order_item, true);
                            }
                        }
                    }
                    $custom_orders = woo_ce_get_option('custom_orders', '');
                    if (!empty($custom_orders)) {
                        foreach ($custom_orders as $custom_order) {
                            if (!empty($custom_order)) {
                                $orders[$key]->{$custom_order} = get_post_meta($order->ID, $custom_order, true);
                            }
                        }
                    }
                }
                $orders[$key] = apply_filters('woo_cd_order', $orders[$key]);
            }
        }
    }
    if ($export_type == 'customers') {
        $customers = array();
        foreach ($orders as $order) {
            if ($duplicate_key = woo_cd_is_duplicate_customer($customers, $order)) {
                $customers[$duplicate_key]->total_spent = $customers[$duplicate_key]->total_spent + $order->purchase_total;
                $customers[$duplicate_key]->total_orders++;
                if ($order->payment_status == 'completed') {
                    $customers[$duplicate_key]->completed_orders++;
                }
            } else {
                $customers[$order->ID] = $order;
                $customers[$order->ID]->total_spent = $order->purchase_total;
                $customers[$order->ID]->completed_orders = 0;
                if ($order->payment_status == 'completed') {
                    $customers[$order->ID]->completed_orders = 1;
                }
                $customers[$order->ID]->total_orders = 1;
            }
        }
        $export->total_rows = count($customers);
        return $customers;
    } else {
        return $orders;
    }
}