function woo_cd_get_coupons() { global $export; $post_type = 'shop_coupon'; $args = array('post_type' => $post_type, 'numberposts' => -1, 'post_status' => woo_ce_post_statuses(), 'cache_results' => false, 'no_found_rows' => false); $export->total_rows = 0; if ($coupons = get_posts($args)) { $export->total_rows = count($coupons); foreach ($coupons as $key => $coupon) { $coupons[$key]->coupon_code = $coupon->post_title; $coupons[$key]->discount_type = woo_cd_format_discount_type(get_post_meta($coupon->ID, 'discount_type', true)); $coupons[$key]->coupon_description = $coupon->post_excerpt; $coupons[$key]->coupon_amount = get_post_meta($coupon->ID, 'coupon_amount', true); $coupons[$key]->individual_use = woo_ce_format_switch(get_post_meta($coupon->ID, 'individual_use', true)); $coupons[$key]->apply_before_tax = woo_ce_format_switch(get_post_meta($coupon->ID, 'apply_before_tax', true)); $coupons[$key]->exclude_sale_items = woo_ce_format_switch(get_post_meta($coupon->ID, 'exclude_sale_items', true)); $coupons[$key]->minimum_amount = get_post_meta($coupon->ID, 'minimum_amount', true); $coupons[$key]->product_ids = woo_cd_convert_product_ids(get_post_meta($coupon->ID, 'product_ids', true)); $coupons[$key]->exclude_product_ids = woo_cd_convert_product_ids(get_post_meta($coupon->ID, 'exclude_product_ids', true)); $coupons[$key]->product_categories = woo_cd_convert_product_ids(get_post_meta($coupon->ID, 'product_categories', true)); $coupons[$key]->exclude_product_categories = woo_cd_convert_product_ids(get_post_meta($coupon->ID, 'exclude_product_categories', true)); $coupons[$key]->customer_email = woo_cd_convert_product_ids(get_post_meta($coupon->ID, 'customer_email', true)); $coupons[$key]->usage_limit = get_post_meta($coupon->ID, 'usage_limit', true); $coupons[$key]->expiry_date = woo_ce_format_date(get_post_meta($coupon->ID, 'expiry_date', true)); } return $coupons; } }
function woo_ce_return_count( $export_type = '', $args = array() ) { global $wpdb; $count_sql = null; $woocommerce_version = woo_get_woo_version(); switch( $export_type ) { case 'product': $post_type = array( 'product', 'product_variation' ); $args = array( 'post_type' => $post_type, 'posts_per_page' => 1, 'fields' => 'ids', 'suppress_filters' => 1 ); $count_query = new WP_Query( $args ); $count = $count_query->found_posts; break; case 'category': $term_taxonomy = 'product_cat'; if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'tag': $term_taxonomy = 'product_tag'; if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'brand': $term_taxonomy = apply_filters( 'woo_ce_brand_term_taxonomy', 'product_brand' ); if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'order': $post_type = 'shop_order'; // Check if this is a WooCommerce 2.2+ instance (new Post Status) if( version_compare( $woocommerce_version, '2.2' ) >= 0 ) $post_status = ( function_exists( 'wc_get_order_statuses' ) ? apply_filters( 'woo_ce_order_post_status', array_keys( wc_get_order_statuses() ) ) : 'any' ); else $post_status = apply_filters( 'woo_ce_order_post_status', woo_ce_post_statuses() ); $args = array( 'post_type' => $post_type, 'posts_per_page' => 1, 'post_status' => $post_status, 'fields' => 'ids' ); $count_query = new WP_Query( $args ); $count = $count_query->found_posts; break; case 'customer': if( $users = woo_ce_return_count( 'user' ) > 1000 ) { $count = sprintf( '~%s+', 1000 ); } else { $post_type = 'shop_order'; $args = array( 'post_type' => $post_type, 'posts_per_page' => -1, 'fields' => 'ids' ); // Check if this is a WooCommerce 2.2+ instance (new Post Status) if( version_compare( $woocommerce_version, '2.2' ) >= 0 ) { $args['post_status'] = apply_filters( 'woo_ce_customer_post_status', array( 'wc-pending', 'wc-on-hold', 'wc-processing', 'wc-completed' ) ); } else { $args['post_status'] = apply_filters( 'woo_ce_customer_post_status', woo_ce_post_statuses() ); $args['tax_query'] = array( array( 'taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array( 'pending', 'on-hold', 'processing', 'completed' ) ), ); } $order_ids = new WP_Query( $args ); $count = $order_ids->found_posts; if( $count > 100 ) { $count = sprintf( '~%s', $count ); } else { $customers = array(); if( $order_ids->posts ) { foreach( $order_ids->posts as $order_id ) { $email = get_post_meta( $order_id, '_billing_email', true ); if( !in_array( $email, $customers ) ) $customers[$order_id] = $email; unset( $email ); } $count = count( $customers ); } } } /* if( false ) { $orders = get_posts( $args ); if( $orders ) { $customers = array(); foreach( $orders as $order ) { $order->email = get_post_meta( $order->ID, '_billing_email', true ); if( empty( $order->email ) ) { if( $order->user_id = get_post_meta( $order->ID, '_customer_user', true ) ) { $user = get_userdata( $order->user_id ); if( $user ) $order->email = $user->user_email; unset( $user ); } else { $order->email = '-'; } } if( !in_array( $order->email, $customers ) ) { $customers[$order->ID] = $order->email; $count++; } } unset( $orders, $order ); } } */ break; case 'user': if( $users = count_users() ) $count = $users['total_users']; break; case 'coupon': $post_type = 'shop_coupon'; if( post_type_exists( $post_type ) ) $count = wp_count_posts( $post_type ); break; case 'subscription': $count = 0; // Check that WooCommerce Subscriptions exists if( class_exists( 'WC_Subscriptions' ) ) { if( method_exists( 'WC_Subscriptions', 'is_large_site' ) ) { // Does this store have roughly more than 3000 Subscriptions if( false === WC_Subscriptions::is_large_site() ) { if( class_exists( 'WC_Subscriptions_Manager' ) ) { // Check that the get_all_users_subscriptions() function exists if( method_exists( 'WC_Subscriptions_Manager', 'get_all_users_subscriptions' ) ) { if( $subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions() ) { foreach( $subscriptions as $key => $user_subscription ) { if( !empty( $user_subscription ) ) { foreach( $user_subscription as $subscription ) $count++; } } unset( $subscriptions, $subscription, $user_subscription ); } } } } else { if( method_exists( 'WC_Subscriptions', 'get_total_subscription_count' ) ) $count = WC_Subscriptions::get_total_subscription_count(); else $count = "~2500"; } } } break; case 'product_vendor': $term_taxonomy = 'shop_vendor'; if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'commission': $post_type = 'shop_commission'; if( post_type_exists( $post_type ) ) $count = wp_count_posts( $post_type ); break; case 'shipping_class': $term_taxonomy = 'product_shipping_class'; if( taxonomy_exists( $term_taxonomy ) ) $count = wp_count_terms( $term_taxonomy ); break; case 'attribute': $attributes = ( function_exists( 'wc_get_attribute_taxonomies' ) ? wc_get_attribute_taxonomies() : array() ); $count = count( $attributes ); break; } if( isset( $count ) || $count_sql ) { if( isset( $count ) ) { if( is_object( $count ) ) { $count = (array)$count; $count = (int)array_sum( $count ); } return $count; } else { if( $count_sql ) $count = $wpdb->get_var( $count_sql ); else $count = 0; } return $count; } else { return 0; } }
function woo_ce_get_coupons($args = array()) { global $export; $limit_volume = -1; $offset = 0; if ($args) { $limit_volume = isset($args['limit_volume']) ? $args['limit_volume'] : false; $offset = isset($args['offset']) ? $args['offset'] : false; $orderby = isset($args['coupon_orderby']) ? $args['coupon_orderby'] : 'ID'; $order = isset($args['coupon_order']) ? $args['coupon_order'] : 'ASC'; } $post_type = 'shop_coupon'; $args = array('post_type' => $post_type, 'orderby' => $orderby, 'order' => $order, 'offset' => $offset, 'posts_per_page' => $limit_volume, 'post_status' => woo_ce_post_statuses(), 'fields' => 'ids', 'suppress_filters' => false); $coupons = array(); $coupon_ids = new WP_Query($args); if ($coupon_ids->posts) { foreach ($coupon_ids->posts as $coupon_id) { $coupons[] = $coupon_id; } unset($coupon_ids, $coupon_id); } return $coupons; }
function woo_ce_get_products($args = array()) { $limit_volume = -1; $offset = 0; $product_categories = false; $product_tags = false; $product_status = false; $product_type = false; $orderby = 'ID'; $order = 'ASC'; if ($args) { $limit_volume = isset($args['limit_volume']) ? $args['limit_volume'] : false; $offset = isset($args['offset']) ? $args['offset'] : false; if (!empty($args['product_categories'])) { $product_categories = $args['product_categories']; } if (!empty($args['product_tags'])) { $product_tags = $args['product_tags']; } if (!empty($args['product_status'])) { $product_status = $args['product_status']; } if (!empty($args['product_type'])) { $product_type = $args['product_type']; } if (isset($args['product_orderby'])) { $orderby = $args['product_orderby']; } if (isset($args['product_order'])) { $order = $args['product_order']; } } $post_type = array('product', 'product_variation'); $args = array('post_type' => $post_type, 'orderby' => $orderby, 'order' => $order, 'offset' => $offset, 'posts_per_page' => $limit_volume, 'post_status' => woo_ce_post_statuses(), 'fields' => 'ids', 'suppress_filters' => false); $args['tax_query'] = array(); // Filter Products by Product Category if ($product_categories) { $term_taxonomy = 'product_cat'; $args['tax_query'][] = array(array('taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_categories)); } // Filter Products by Product Tag if ($product_tags) { $term_taxonomy = 'product_tag'; $args['tax_query'][] = array(array('taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_tags)); } if ($product_status) { $args['post_status'] = woo_ce_post_statuses($product_status, true); } if ($product_type) { if (in_array('variation', $product_type) && count($product_type) == 1) { $args['post_type'] = array('product_variation'); } if (!empty($product_type)) { $args['tax_query'] = array(array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $product_type)); } else { unset($args['meta_query']); } } $products = array(); $product_ids = new WP_Query($args); if ($product_ids->posts) { foreach ($product_ids->posts as $product_id) { $product = get_post($product_id); // Filter out variations that don't have a Parent Product that exists if ($product->post_type == 'product_variation') { // Check if Parent exists if ($product->post_parent) { if (!get_post($product->post_parent)) { unset($product_id, $product); continue; } } } if (isset($product_id)) { $products[] = $product_id; } } unset($product_ids, $product_id); } return $products; }
function woo_ce_get_products($args = array()) { $limit_volume = -1; $offset = 0; $product_categories = false; $product_tags = false; $product_status = false; $product_type = false; if ($args) { $limit_volume = $args['limit_volume']; $offset = $args['offset']; if (!empty($args['product_categories'])) { $product_categories = $args['product_categories']; } if (!empty($args['product_tags'])) { $product_tags = $args['product_tags']; } if (!empty($args['product_status'])) { $product_status = $args['product_status']; } if (!empty($args['product_type'])) { $product_type = $args['product_type']; } } $post_type = array('product', 'product_variation'); $args = array('post_type' => $post_type, 'numberposts' => $limit_volume, 'offset' => $offset, 'orderby' => 'ID', 'order' => 'ASC', 'post_status' => woo_ce_post_statuses()); if ($product_categories) { $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $product_categories)); } if ($product_tags) { $args['tax_query'] = array(array('taxonomy' => 'product_tag', 'field' => 'id', 'terms' => $product_tags)); } if ($product_status) { $args['post_status'] = woo_ce_post_statuses($product_status, true); } if ($product_type) { if (in_array('variation', $product_type)) { $args['post_type'] = 'product_variation'; } else { $args['tax_query'] = array(array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $product_type)); } } $products = get_posts($args); if ($products) { $weight_unit = get_option('woocommerce_weight_unit'); $dimension_unit = get_option('woocommerce_dimension_unit'); $height_unit = $dimension_unit; $width_unit = $dimension_unit; $length_unit = $dimension_unit; foreach ($products as $key => $product) { $products[$key]->parent_id = ''; $products[$key]->parent_sku = ''; if ($product->post_type == 'product_variation') { $products[$key]->parent_id = $product->post_parent; $products[$key]->parent_sku = get_post_meta($product->post_parent, '_sku', true); } $products[$key]->product_id = $product->ID; $products[$key]->sku = get_post_meta($product->ID, '_sku', true); $products[$key]->name = get_the_title($product->ID); $products[$key]->description = woo_ce_clean_html($product->post_content); $products[$key]->regular_price = get_post_meta($product->ID, '_regular_price', true); $products[$key]->price = get_post_meta($product->ID, '_price', true); if (!empty($products[$key]->regular_price) && $products[$key]->regular_price != $products[$key]->price) { $products[$key]->price = $products[$key]->regular_price; } $products[$key]->sale_price = get_post_meta($product->ID, '_sale_price', true); $products[$key]->sale_price_dates_from = woo_ce_format_sale_price_dates(get_post_meta($product->ID, '_sale_price_dates_from', true)); $products[$key]->sale_price_dates_to = woo_ce_format_sale_price_dates(get_post_meta($product->ID, '_sale_price_dates_to', true)); $products[$key]->slug = $product->post_name; $products[$key]->permalink = get_permalink($product->ID); $products[$key]->excerpt = woo_ce_clean_html($product->post_excerpt); $products[$key]->type = woo_ce_get_product_assoc_type($product->ID); if ($product->post_type == 'product_variation') { $products[$key]->type = __('Variation', 'woo_ce'); } $products[$key]->visibility = woo_ce_format_visibility(get_post_meta($product->ID, '_visibility', true)); $products[$key]->featured = woo_ce_format_switch(get_post_meta($product->ID, '_featured', true)); $products[$key]->virtual = woo_ce_format_switch(get_post_meta($product->ID, '_virtual', true)); $products[$key]->downloadable = woo_ce_format_switch(get_post_meta($product->ID, '_downloadable', true)); $products[$key]->weight = get_post_meta($product->ID, '_weight', true); $products[$key]->weight_unit = $weight_unit; $products[$key]->height = get_post_meta($product->ID, '_height', true); $products[$key]->height_unit = $height_unit; $products[$key]->width = get_post_meta($product->ID, '_width', true); $products[$key]->width_unit = $width_unit; $products[$key]->length = get_post_meta($product->ID, '_length', true); $products[$key]->length_unit = $length_unit; $products[$key]->category = woo_ce_get_product_assoc_categories($product->ID); $products[$key]->tag = woo_ce_get_product_assoc_tags($product->ID); $products[$key]->manage_stock = woo_ce_format_switch(get_post_meta($product->ID, '_manage_stock', true)); $products[$key]->allow_backorders = woo_ce_format_switch(get_post_meta($product->ID, '_backorders', true)); $products[$key]->sold_individually = woo_ce_format_switch(get_post_meta($product->ID, '_sold_individually', true)); $products[$key]->upsell_ids = woo_ce_convert_product_ids(get_post_meta($product->ID, '_upsell_ids', true)); $products[$key]->crosssell_ids = woo_ce_convert_product_ids(get_post_meta($product->ID, '_crosssell_ids', true)); $products[$key]->quantity = get_post_meta($product->ID, '_stock', true); $products[$key]->stock_status = woo_ce_format_stock_status(get_post_meta($product->ID, '_stock_status', true)); $products[$key]->image = woo_ce_get_product_assoc_featured_image($product->ID); $products[$key]->product_gallery = woo_ce_get_product_assoc_product_gallery($product->ID); $products[$key]->tax_status = woo_ce_format_tax_status(get_post_meta($product->ID, '_tax_status', true)); $products[$key]->tax_class = woo_ce_format_tax_class(get_post_meta($product->ID, '_tax_class', true)); $products[$key]->product_url = get_post_meta($product->ID, '_product_url', true); $products[$key]->button_text = get_post_meta($product->ID, '_button_text', true); $products[$key]->file_download = woo_ce_get_product_assoc_file_downloads($product->ID); $products[$key]->download_limit = get_post_meta($product->ID, '_download_limit', true); $products[$key]->download_expiry = get_post_meta($product->ID, '_download_expiry', true); $products[$key]->purchase_note = get_post_meta($product->ID, '_purchase_note', true); $products[$key]->product_status = woo_ce_format_product_status($product->post_status); $products[$key]->comment_status = woo_ce_format_comment_status($product->comment_status); if ($attributes = woo_ce_get_product_attributes()) { if ($product->post_type == 'product_variation') { foreach ($attributes as $attribute) { $products[$key]->{'attribute_' . $attribute->attribute_name} = get_post_meta($product->ID, sprintf('attribute_pa_%s', $attribute->attribute_name), true); } } else { $products[$key]->attributes = maybe_unserialize(get_post_meta($product->ID, '_product_attributes', true)); if (!empty($products[$key]->attributes)) { foreach ($attributes as $attribute) { if (isset($products[$key]->attributes['pa_' . $attribute->attribute_name])) { $products[$key]->{'attribute_' . $attribute->attribute_name} = woo_ce_get_product_assoc_attributes($product->ID, $products[$key]->attributes['pa_' . $attribute->attribute_name]); } } } } } $products[$key] = apply_filters('woo_ce_product_item', $products[$key], $product->ID); } } return $products; }
function woo_ce_return_count($dataset) { global $wpdb; $count_sql = null; switch ($dataset) { case 'products': $post_type = 'product'; $args = array('post_type' => $post_type, 'posts_per_page' => 1); $query = new WP_Query($args); $count = $query->found_posts; break; case 'categories': $term_taxonomy = 'product_cat'; $count = wp_count_terms($term_taxonomy); break; case 'tags': $term_taxonomy = 'product_tag'; $count = wp_count_terms($term_taxonomy); break; case 'orders': $post_type = 'shop_order'; $args = array('post_type' => $post_type, 'posts_per_page' => 1); $query = new WP_Query($args); $count = $query->found_posts; break; case 'customers': $post_type = 'shop_order'; $args = array('post_type' => $post_type, 'posts_per_page' => -1, 'post_status' => woo_ce_post_statuses(), 'tax_query' => array(array('taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array('pending', 'on-hold', 'processing', 'completed'))), 'fields' => 'ids'); $query = new WP_Query($args); $count = $query->found_posts; if ($count > 100) { $count = sprintf('~%s *', $count); } else { $customers = array(); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $email = get_post_meta(get_the_ID(), '_billing_email', true); if (!in_array($email, $customers)) { $customers[get_the_ID()] = $email; } unset($email); } $count = count($customers); } wp_reset_postdata(); } /* if( false ) { $orders = get_posts( $args ); if( $orders ) { $customers = array() ; foreach( $orders as $order ) { $order->email = get_post_meta( $order->ID, '_billing_email', true ); if( empty( $order->email ) ) { if( $order->user_id = get_post_meta( $order->ID, '_customer_user', true ) ) { $user = get_userdata( $order->user_id ); if( $user ) $order->email = $user->user_email; unset( $user ); } else { $order->email = '-'; } } if( !in_array( $order->email, $customers ) ) { $customers[$order->ID] = $order->email; $count++; } } unset( $orders, $order ); } } */ break; case 'coupons': $post_type = 'shop_coupon'; $count = wp_count_posts($post_type); break; } if (isset($count) || $count_sql) { if (isset($count)) { $count = woo_ce_count_object($count); return $count; } else { if ($count_sql) { $count = $wpdb->get_var($count_sql); } else { $count = 0; } } return $count; } else { return 0; } }
function woo_ce_get_coupons( $args = array() ) { global $export; $limit_volume = -1; $offset = 0; $discount_types = false; if( $args ) { $limit_volume = ( isset( $args['limit_volume'] ) ? $args['limit_volume'] : false ); $offset = ( isset( $args['offset'] ) ? $args['offset'] : false ); $orderby = ( isset( $args['coupon_orderby'] ) ? $args['coupon_orderby'] : 'ID' ); $order = ( isset( $args['coupon_order'] ) ? $args['coupon_order'] : 'ASC' ); if( !empty( $args['coupon_discount_types'] ) ) $discount_types = $args['coupon_discount_types']; } $post_type = 'shop_coupon'; $args = array( 'post_type' => $post_type, 'orderby' => $orderby, 'order' => $order, 'offset' => $offset, 'posts_per_page' => $limit_volume, 'post_status' => woo_ce_post_statuses(), 'fields' => 'ids', 'suppress_filters' => false ); if( $discount_types ) { $args['meta_query'] = array(); $args['meta_query'][] = array( 'key' => 'discount_type', 'value' => $discount_types ); } $coupons = array(); // Allow other developers to bake in their own filters $args = apply_filters( 'woo_ce_get_coupons_args', $args ); $coupon_ids = new WP_Query( $args ); if( $coupon_ids->posts ) { foreach( $coupon_ids->posts as $coupon_id ) $coupons[] = $coupon_id; unset( $coupon_ids, $coupon_id ); } return $coupons; }
function woo_ce_get_products( $args = array() ) { global $export; $limit_volume = -1; $offset = 0; $product_categories = false; $product_tags = false; $product_brands = false; $product_vendors = false; $product_status = false; $product_type = false; $product_stock = false; $product_status = false; $product_language = false; $orderby = 'ID'; $order = 'ASC'; if( $args ) { $limit_volume = ( isset( $args['limit_volume'] ) ? $args['limit_volume'] : false ); $offset = ( isset( $args['offset'] ) ? $args['offset'] : false ); if( !empty( $args['product_categories'] ) ) $product_categories = $args['product_categories']; if( !empty( $args['product_tags'] ) ) $product_tags = $args['product_tags']; if( !empty( $args['product_brands'] ) ) $product_brands = $args['product_brands']; if( !empty( $args['product_vendors'] ) ) $product_vendors = $args['product_vendors']; if( !empty( $args['product_status'] ) ) $product_status = $args['product_status']; if( !empty( $args['product_type'] ) ) $product_type = $args['product_type']; if( !empty( $args['product_stock'] ) ) $product_stock = $args['product_stock']; if( !empty( $args['product_language'] ) ) $product_language = $args['product_language']; if( isset( $args['product_orderby'] ) ) $orderby = $args['product_orderby']; if( isset( $args['product_order'] ) ) $order = $args['product_order']; } $post_type = apply_filters( 'woo_ce_get_products_post_type', array( 'product' ) ); $post_status = apply_filters( 'woo_ce_get_products_status', array( 'publish', 'pending', 'draft', 'future', 'private' ) ); $args = array( 'post_type' => $post_type, 'orderby' => $orderby, 'order' => $order, 'offset' => $offset, 'posts_per_page' => $limit_volume, 'post_status' => woo_ce_post_statuses( $post_status, true ), 'fields' => 'ids', 'suppress_filters' => false ); // Filter Products by Product Category if( $product_categories ) { $term_taxonomy = 'product_cat'; // Check if tax_query has been created if( !isset( $args['tax_query'] ) ) $args['tax_query'] = array(); $args['tax_query'][] = array( array( 'taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_categories ) ); } // Filter Products by Product Tag if( $product_tags ) { $term_taxonomy = 'product_tag'; // Check if tax_query has been created if( !isset( $args['tax_query'] ) ) $args['tax_query'] = array(); $args['tax_query'][] = array( array( 'taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_tags ) ); } // WooCommerce Brands Addon - http://woothemes.com/woocommerce/ if( $product_brands ) { $term_taxonomy = apply_filters( 'woo_ce_brand_term_taxonomy', 'product_brand' ); // Check if tax_query has been created if( !isset( $args['tax_query'] ) ) $args['tax_query'] = array(); $args['tax_query'][] = array( array( 'taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_brands ) ); } // Product Vendors - http://www.woothemes.com/products/product-vendors/ if( $product_vendors ) { $term_taxonomy = 'shop_vendor'; // Check if tax_query has been created if( !isset( $args['tax_query'] ) ) $args['tax_query'] = array(); $args['tax_query'][] = array( array( 'taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_vendors ) ); } // Filter Products by Language if( $product_language ) { global $sitepress; // See if our WPML integration magic sticks remove_filter( 'posts_where' , array( $sitepress, 'posts_where_filter' ), 10 ); add_filter( 'posts_where' , 'woo_ce_wp_query_product_where_override_language' ); } // Filter Products by Post Status if( $product_status ) $args['post_status'] = woo_ce_post_statuses( $product_status, true ); // Filter Products by Product Type if( $product_type ) { // Check if we are just exporting variations if( in_array( 'variation', $product_type ) && count( $product_type ) == 1 ) $args['post_type'] = array( 'product_variation' ); $args['meta_query'] = array( 'relation' => 'OR' ); if( in_array( 'downloadable', $product_type ) ) { $args['meta_query'][] = array( 'key' => '_downloadable', 'value' => 'yes', 'compare' => 'EXISTS' ); } if( in_array( 'virtual', $product_type ) ) { $args['meta_query'][] = array( 'key' => '_virtual', 'value' => 'yes' ); } // Remove non-Term based Product Types before we tack on our tax_query $term_product_type = $product_type; foreach( $term_product_type as $key => $type ) { if( in_array( $type, array( 'downloadable', 'virtual', 'variation' ) ) ) unset( $term_product_type[$key] ); } if( !empty( $term_product_type ) ) { $args['tax_query'][] = array( array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $term_product_type ) ); } else { unset( $args['meta_query'] ); } unset( $term_product_type ); } $products = array(); // Allow other developers to bake in their own filters $args = apply_filters( 'woo_ce_get_products_args', $args ); $product_ids = new WP_Query( $args ); if( $product_ids->posts ) { foreach( $product_ids->posts as $product_id ) { $product = get_post( $product_id ); // Filter out variations that don't have a Parent Product that exists if( isset( $product->post_type ) && $product->post_type == 'product_variation' ) { // Check if Parent exists if( $product->post_parent ) { if( !get_post( $product->post_parent ) ) { unset( $product_id, $product ); continue; } } } // Filter out Products based on the Stock Status and Quantity if( $product_stock ) { $manage_stock = get_post_meta( $product_id, '_manage_stock', true ); $stock_status = get_post_meta( $product_id, '_stock_status', true ); $quantity = get_post_meta( $product_id, '_stock', true ); $quantity = ( function_exists( 'wc_stock_amount' ) ? wc_stock_amount( $quantity ) : $quantity ); switch( $product_stock ) { case 'outofstock': if( ( $manage_stock == 'yes' && $quantity > 0 ) || $stock_status <> 'outofstock' ) { unset( $product_id, $product ); continue; } break; case 'instock': if( ( $manage_stock == 'yes' && $quantity == 0 ) || $stock_status <> 'instock' ) { unset( $product_id, $product ); continue; } break; } unset( $stock_status ); } if( isset( $product_id ) ) $products[] = $product_id; // Include Variables in a new WP_Query if a tax_query filter is used or WPML exists if( isset( $args['tax_query'] ) || woo_ce_is_wpml_activated() ) { $term_taxonomy = 'product_type'; if( has_term( 'variable', $term_taxonomy, $product_id ) && ( $product_type !== false && in_array( 'variation', $product_type ) ) ) { $variable_args = array( 'post_type' => 'product_variation', 'orderby' => $orderby, 'order' => $order, 'post_parent' => $product_id, 'post_status' => array( 'publish' ), 'fields' => 'ids' ); $variables = array(); $variable_ids = new WP_Query( $variable_args ); if( $variable_ids->posts ) { foreach( $variable_ids->posts as $variable_id ) { // Check we're not including a duplicate Product ID if( !in_array( $variable_id, $product_ids->posts ) ) $products[] = $variable_id; } } unset( $variables, $variable_ids, $variable_args, $variable_id ); } } } // Check if the global $export has been created if( isset( $export ) ) $export->total_rows = count( $products ); unset( $product_ids, $product_id ); } // Filter Products by Language if( $product_language ) { global $sitepress; add_filter( 'posts_where' , array( $sitepress, 'posts_where_filter' ), 10, 2 ); remove_filter( 'posts_where' , 'woo_ce_wp_query_product_where_override_language' ); } return $products; }
function woo_ce_get_commissions( $args = array() ) { global $export; $limit_volume = -1; $offset = 0; if( $args ) { $product_vendors = ( isset( $args['commission_product_vendors'] ) ? $args['commission_product_vendors'] : false ); $status = ( isset( $args['commission_status'] ) ? $args['commission_status'] : false ); $limit_volume = ( isset( $args['limit_volume'] ) ? $args['limit_volume'] : false ); $offset = ( isset( $args['offset'] ) ? $args['offset'] : false ); $orderby = ( isset( $args['commission_orderby'] ) ? $args['commission_orderby'] : 'ID' ); $order = ( isset( $args['commission_order'] ) ? $args['commission_order'] : 'ASC' ); $commission_dates_filter = ( isset( $args['commission_dates_filter'] ) ? $args['commission_dates_filter'] : false ); switch( $commission_dates_filter ) { case 'today': $commission_dates_from = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n' ), date( 'd' ) ) ); $commission_dates_to = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n' ), date( 'd' ) ) ); break; case 'yesterday': $commission_dates_from = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( '-2 days' ) ), date( 'd', strtotime( '-2 days' ) ) ) ); $commission_dates_to = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( '-1 days' ) ), date( 'd', strtotime( '-1 days' ) ) ) ); break; case 'current_week': $commission_dates_from = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( 'this Monday' ) ), date( 'd', strtotime( 'this Monday' ) ) ) ); $commission_dates_to = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( 'next Sunday' ) ), date( 'd', strtotime( 'next Sunday' ) ) ) ); break; case 'last_week': $commission_dates_from = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( 'last Monday' ) ), date( 'd', strtotime( 'last Monday' ) ) ) ); $commission_dates_to = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( 'last Sunday' ) ), date( 'd', strtotime( 'last Sunday' ) ) ) ); break; case 'current_month': $commission_dates_from = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n' ), 1 ) ); $commission_dates_to = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( '+1 month' ) ), 0 ) ); break; case 'last_month': $commission_dates_from = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( '-1 month' ) ), 1 ) ); $commission_dates_to = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n' ), 0 ) ); break; case 'last_quarter': break; case 'manual': $commission_dates_from = woo_ce_format_order_date( $args['commission_dates_from'] ); $commission_dates_to = woo_ce_format_order_date( $args['commission_dates_to'] ); break; case 'variable': $commission_filter_date_variable = $args['commission_dates_filter_variable']; $commission_filter_date_variable_length = $args['commission_dates_filter_variable_length']; if( $commission_filter_date_variable !== false && $commission_filter_date_variable_length !== false ) { $commission_filter_date_strtotime = sprintf( '-%d %s', $commission_filter_date_variable, $commission_filter_date_variable_length ); $commission_dates_from = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n', strtotime( $commission_filter_date_strtotime ) ), date( 'd', strtotime( $commission_filter_date_strtotime ) ) ) ); $commission_dates_to = date( 'd-m-Y', mktime( 0, 0, 0, date( 'n' ), date( 'd' ) ) ); unset( $commission_filter_date_variable, $commission_filter_date_variable_length, $commission_filter_date_strtotime ); } break; default: $commission_dates_from = false; $commission_dates_to = false; break; } if( $commission_dates_from && $commission_dates_to ) { $commission_dates_from = strtotime( $commission_dates_from ); $commission_dates_to = explode( '-', $commission_dates_to ); // Check that a valid date was provided if( isset( $commission_dates_to[0] ) && isset( $commission_dates_to[1] ) && isset( $commission_dates_to[2] ) ) $commission_dates_to = strtotime( date( 'd-m-Y', mktime( 0, 0, 0, $commission_dates_to[1], $commission_dates_to[0]+1, $commission_dates_to[2] ) ) ); else $commission_dates_to = false; } } $post_type = 'shop_commission'; $args = array( 'post_type' => $post_type, 'orderby' => $orderby, 'order' => $order, 'offset' => $offset, 'posts_per_page' => $limit_volume, 'post_status' => woo_ce_post_statuses(), 'fields' => 'ids', 'suppress_filters' => false ); if( !empty( $product_vendors ) ) { $args['meta_query'][] = array( 'key' => '_commission_vendor', 'value' => $product_vendors, 'compare' => 'IN' ); } if( !empty( $status ) ) { $args['meta_query'][] = array( 'key' => '_paid_status', 'value' => $status, 'compare' => 'IN' ); } $commissions = array(); // Allow other developers to bake in their own filters $args = apply_filters( 'woo_ce_get_commissions_args', $args ); $commission_ids = new WP_Query( $args ); if( $commission_ids->posts ) { foreach( $commission_ids->posts as $commission_id ) { // Get Commission details $commission = get_post( $commission_id ); // Filter Commission dates by dropping those outside the date range if( $commission_dates_from && $commission_dates_to ) { if( ( strtotime( $commission->post_date ) > $commission_dates_from ) && ( strtotime( $commission->post_date ) < $commission_dates_to ) ) { // Do nothing } else { unset( $commission ); continue; } } $commissions[] = $commission_id; } unset( $commission_ids, $commission_id ); } return $commissions; }
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; } }