Ejemplo n.º 1
0
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;
    }
}
Ejemplo n.º 2
0
function woo_ce_get_product_data($product_id = 0, $args = array())
{
    // Get Product defaults
    $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;
    $product = get_post($product_id);
    $_product = function_exists('wc_get_product') ? wc_get_product($product_id) : false;
    $product->parent_id = '';
    $product->parent_sku = '';
    if ($product->post_type == 'product_variation') {
        // Assign Parent ID for Variants then check if Parent exists
        if ($product->parent_id = $product->post_parent) {
            $product->parent_sku = get_post_meta($product->post_parent, '_sku', true);
        } else {
            $product->parent_id = '';
        }
    }
    $product->product_id = $product_id;
    $product->sku = get_post_meta($product_id, '_sku', true);
    $product->name = get_the_title($product_id);
    $product->permalink = get_permalink($product_id);
    $product->product_url = method_exists($_product, 'get_permalink') ? $_product->get_permalink() : get_permalink($product_id);
    $product->slug = $product->post_name;
    $product->description = $product->post_content;
    $product->excerpt = $product->post_excerpt;
    $product->regular_price = get_post_meta($product_id, '_regular_price', true);
    // Check that a valid price has been provided and that wc_format_localized_price() exists
    if (isset($product->regular_price) && $product->regular_price != '' && function_exists('wc_format_localized_price')) {
        $product->regular_price = wc_format_localized_price($product->regular_price);
    }
    $product->price = get_post_meta($product_id, '_price', true);
    if ($product->regular_price != '' && $product->regular_price != $product->price) {
        $product->price = $product->regular_price;
    }
    // Check that a valid price has been provided and that wc_format_localized_price() exists
    if (isset($product->price) && $product->price != '' && function_exists('wc_format_localized_price')) {
        $product->price = wc_format_localized_price($product->price);
    }
    $product->sale_price = get_post_meta($product_id, '_sale_price', true);
    // Check that a valid price has been provided and that wc_format_localized_price() exists
    if (isset($product->sale_price) && $product->sale_price != '' && function_exists('wc_format_localized_price')) {
        $product->sale_price = wc_format_localized_price($product->sale_price);
    }
    $product->sale_price_dates_from = woo_ce_format_sale_price_dates(get_post_meta($product_id, '_sale_price_dates_from', true));
    $product->sale_price_dates_to = woo_ce_format_sale_price_dates(get_post_meta($product_id, '_sale_price_dates_to', true));
    $product->post_date = woo_ce_format_date($product->post_date);
    $product->post_modified = woo_ce_format_date($product->post_modified);
    $product->type = woo_ce_get_product_assoc_type($product_id);
    if ($product->post_type == 'product_variation') {
        $product->type = __('Variation', 'woo_ce');
    }
    $product->visibility = woo_ce_format_visibility(get_post_meta($product_id, '_visibility', true));
    $product->featured = woo_ce_format_switch(get_post_meta($product_id, '_featured', true));
    $product->virtual = woo_ce_format_switch(get_post_meta($product_id, '_virtual', true));
    $product->downloadable = woo_ce_format_switch(get_post_meta($product_id, '_downloadable', true));
    $product->weight = get_post_meta($product_id, '_weight', true);
    $product->weight_unit = $product->weight != '' ? $weight_unit : '';
    $product->height = get_post_meta($product_id, '_height', true);
    $product->height_unit = $product->height != '' ? $height_unit : '';
    $product->width = get_post_meta($product_id, '_width', true);
    $product->width_unit = $product->width != '' ? $width_unit : '';
    $product->length = get_post_meta($product_id, '_length', true);
    $product->length_unit = $product->length != '' ? $length_unit : '';
    $product->category = woo_ce_get_product_assoc_categories($product_id, $product->parent_id);
    $product->tag = woo_ce_get_product_assoc_tags($product_id);
    $product->manage_stock = woo_ce_format_switch(get_post_meta($product_id, '_manage_stock', true));
    $product->allow_backorders = woo_ce_format_switch(get_post_meta($product_id, '_backorders', true));
    $product->sold_individually = woo_ce_format_switch(get_post_meta($product_id, '_sold_individually', true));
    $product->upsell_ids = woo_ce_get_product_assoc_upsell_ids($product_id);
    $product->crosssell_ids = woo_ce_get_product_assoc_crosssell_ids($product_id);
    $product->quantity = get_post_meta($product_id, '_stock', true);
    $product->stock_status = woo_ce_format_stock_status(get_post_meta($product_id, '_stock_status', true), $product->quantity);
    $product->image = woo_ce_get_product_assoc_featured_image($product_id);
    $product->product_gallery = woo_ce_get_product_assoc_product_gallery($product_id);
    $product->tax_status = woo_ce_format_tax_status(get_post_meta($product_id, '_tax_status', true));
    $product->tax_class = woo_ce_format_tax_class(get_post_meta($product_id, '_tax_class', true));
    $product->external_url = get_post_meta($product_id, '_product_url', true);
    $product->button_text = get_post_meta($product_id, '_button_text', true);
    $product->file_download = woo_ce_get_product_assoc_file_downloads($product_id);
    $product->download_limit = get_post_meta($product_id, '_download_limit', true);
    $product->download_expiry = get_post_meta($product_id, '_download_expiry', true);
    $product->download_type = woo_ce_format_download_type(get_post_meta($product_id, '_download_type', true));
    $product->purchase_note = get_post_meta($product_id, '_purchase_note', true);
    $product->product_status = woo_ce_format_product_status($product->post_status);
    $product->enable_reviews = woo_ce_format_comment_status($product->comment_status);
    $product->menu_order = $product->menu_order;
    // Attributes
    // Scan for global Attributes first
    if ($attributes = woo_ce_get_product_attributes()) {
        if ($product->post_type == 'product_variation') {
            // We're dealing with a single Variation, strap yourself in.
            foreach ($attributes as $attribute) {
                $attribute_value = get_post_meta($product_id, sprintf('attribute_pa_%s', $attribute->attribute_name), true);
                if (!empty($attribute_value)) {
                    $term_id = term_exists($attribute_value, sprintf('pa_%s', $attribute->attribute_name));
                    if ($term_id !== 0 && $term_id !== null && !is_wp_error($term_id)) {
                        $term = get_term($term_id['term_id'], sprintf('pa_%s', $attribute->attribute_name));
                        $attribute_value = $term->name;
                        unset($term);
                    }
                    unset($term_id);
                }
                $product->{'attribute_' . $attribute->attribute_name} = $attribute_value;
                unset($attribute_value);
            }
        } else {
            // Either the Variation Parent or a Simple Product, scan for global and custom Attributes
            $product->attributes = maybe_unserialize(get_post_meta($product_id, '_product_attributes', true));
            if (!empty($product->attributes)) {
                // Check for taxonomy-based attributes
                foreach ($attributes as $attribute) {
                    if (isset($product->attributes['pa_' . $attribute->attribute_name])) {
                        $product->{'attribute_' . $attribute->attribute_name} = woo_ce_get_product_assoc_attributes($product_id, $product->attributes['pa_' . $attribute->attribute_name], 'product');
                    } else {
                        $product->{'attribute_' . $attribute->attribute_name} = woo_ce_get_product_assoc_attributes($product_id, $attribute, 'global');
                    }
                }
                // Check for per-Product attributes (custom)
                foreach ($product->attributes as $key => $attribute) {
                    if ($attribute['is_taxonomy'] == 0) {
                        if (!isset($product->{'attribute_' . $key})) {
                            $product->{'attribute_' . $key} = $attribute['value'];
                        }
                    }
                }
            }
        }
    }
    // Advanced Google Product Feed - http://plugins.leewillis.co.uk/downloads/wp-e-commerce-product-feeds/
    if (function_exists('woocommerce_gpf_install')) {
        $product->gpf_data = get_post_meta($product_id, '_woocommerce_gpf_data', true);
        $product->gpf_availability = isset($product->gpf_data['availability']) ? woo_ce_format_gpf_availability($product->gpf_data['availability']) : '';
        $product->gpf_condition = isset($product->gpf_data['condition']) ? woo_ce_format_gpf_condition($product->gpf_data['condition']) : '';
        $product->gpf_brand = isset($product->gpf_data['brand']) ? $product->gpf_data['brand'] : '';
        $product->gpf_product_type = isset($product->gpf_data['product_type']) ? $product->gpf_data['product_type'] : '';
        $product->gpf_google_product_category = isset($product->gpf_data['google_product_category']) ? $product->gpf_data['google_product_category'] : '';
        $product->gpf_gtin = isset($product->gpf_data['gtin']) ? $product->gpf_data['gtin'] : '';
        $product->gpf_mpn = isset($product->gpf_data['mpn']) ? $product->gpf_data['mpn'] : '';
        $product->gpf_gender = isset($product->gpf_data['gender']) ? $product->gpf_data['gender'] : '';
        $product->gpf_age_group = isset($product->gpf_data['age_group']) ? $product->gpf_data['age_group'] : '';
        $product->gpf_color = isset($product->gpf_data['color']) ? $product->gpf_data['color'] : '';
        $product->gpf_size = isset($product->gpf_data['size']) ? $product->gpf_data['size'] : '';
    }
    // All in One SEO Pack - http://wordpress.org/extend/plugins/all-in-one-seo-pack/
    if (function_exists('aioseop_activate')) {
        $product->aioseop_keywords = get_post_meta($product_id, '_aioseop_keywords', true);
        $product->aioseop_description = get_post_meta($product_id, '_aioseop_description', true);
        $product->aioseop_title = get_post_meta($product_id, '_aioseop_title', true);
        $product->aioseop_titleatr = get_post_meta($product_id, '_aioseop_titleatr', true);
        $product->aioseop_menulabel = get_post_meta($product_id, '_aioseop_menulabel', true);
    }
    // WordPress SEO - http://wordpress.org/plugins/wordpress-seo/
    if (function_exists('wpseo_admin_init')) {
        $product->wpseo_focuskw = get_post_meta($product_id, '_yoast_wpseo_focuskw', true);
        $product->wpseo_metadesc = get_post_meta($product_id, '_yoast_wpseo_metadesc', true);
        $product->wpseo_title = get_post_meta($product_id, '_yoast_wpseo_title', true);
        $product->wpseo_googleplus_description = get_post_meta($product_id, '_yoast_wpseo_google-plus-description', true);
        $product->wpseo_opengraph_description = get_post_meta($product_id, '_yoast_wpseo_opengraph-description', true);
    }
    // Ultimate SEO - http://wordpress.org/plugins/seo-ultimate/
    if (function_exists('su_wp_incompat_notice')) {
        $product->useo_meta_title = get_post_meta($product_id, '_su_title', true);
        $product->useo_meta_description = get_post_meta($product_id, '_su_description', true);
        $product->useo_meta_keywords = get_post_meta($product_id, '_su_keywords', true);
        $product->useo_social_title = get_post_meta($product_id, '_su_og_title', true);
        $product->useo_social_description = get_post_meta($product_id, '_su_og_description', true);
        $product->useo_meta_noindex = get_post_meta($product_id, '_su_meta_robots_noindex', true);
        $product->useo_meta_noautolinks = get_post_meta($product_id, '_su_disable_autolinks', true);
    }
    // WooCommerce MSRP Pricing - http://woothemes.com/woocommerce/
    if (function_exists('woocommerce_msrp_activate')) {
        $product->msrp = get_post_meta($product_id, '_msrp_price', true);
        if ($product->msrp == false && $product->post_type == 'product_variation') {
            $product->msrp = get_post_meta($product_id, '_msrp', true);
        }
        // Check that a valid price has been provided and that wc_format_localized_price() exists
        if (isset($product->msrp) && $product->msrp != '' && function_exists('wc_format_localized_price')) {
            $product->msrp = wc_format_localized_price($product->msrp);
        }
    }
    // Allow Plugin/Theme authors to add support for additional Product columns
    $product = apply_filters('woo_ce_product_item', $product, $product_id);
    return $product;
}
Ejemplo n.º 3
0
function woo_ce_get_order_data( $order_id = 0, $export_type = 'order', $args = array(), $fields = array() ) {

	global $export;

	$defaults = array(
		'order_items' => 'combined',
		'order_items_types' => array_keys( woo_ce_get_order_items_types() )
	);
	$args = wp_parse_args( $args, $defaults );

	// Get WooCommerce Order details
	$order = woo_ce_get_order_wc_data( $order_id );

	$order->ID = ( isset( $order->id ) ? $order->id : $order_id );
	$order->payment_status = $order->status;
	// Check if this is a pre-WooCommerce 2.2 instance
	$woocommerce_version = woo_get_woo_version();
	$order->post_status = woo_ce_format_post_status( $order->post_status );
	$order->user_id = get_post_meta( $order_id, '_customer_user', true );
	if( $order->user_id == 0 )
		$order->user_id = '';
	$order->user_name = woo_ce_get_username( $order->user_id );
	$order->user_role = woo_ce_format_user_role_label( woo_ce_get_user_role( $order->user_id ) );
	$order->purchase_total = get_post_meta( $order_id, '_order_total', true );
	$order->order_currency = get_post_meta( $order_id, '_order_currency', true );
	$order->billing_first_name = get_post_meta( $order_id, '_billing_first_name', true );
	$order->billing_last_name = get_post_meta( $order_id, '_billing_last_name', true );
	if( empty( $order->billing_first_name ) && empty( $order->billing_first_name ) )
		$order->billing_full_name = '';
	else
		$order->billing_full_name = $order->billing_first_name . ' ' . $order->billing_last_name;
	$order->billing_company = get_post_meta( $order_id, '_billing_company', true );
	$order->billing_address = '';
	$order->billing_address_1 = get_post_meta( $order_id, '_billing_address_1', true );
	$order->billing_address_2 = get_post_meta( $order_id, '_billing_address_2', true );
	if( !empty( $order->billing_address_2 ) )
		$order->billing_address = sprintf( apply_filters( 'woo_ce_get_order_data_billing_address', '%s %s' ), $order->billing_address_1, $order->billing_address_2 );
	else
		$order->billing_address = $order->billing_address_1;
	$order->billing_city = get_post_meta( $order_id, '_billing_city', true );
	$order->billing_postcode = get_post_meta( $order_id, '_billing_postcode', true );
	$order->billing_state = get_post_meta( $order_id, '_billing_state', true );
	$order->billing_country = get_post_meta( $order_id, '_billing_country', true );
	$order->billing_state_full = woo_ce_expand_state_name( $order->billing_country, $order->billing_state );
	$order->billing_country_full = woo_ce_expand_country_name( $order->billing_country );
	$order->billing_phone = get_post_meta( $order_id, '_billing_phone', true );
	$order->billing_email = get_post_meta( $order_id, '_billing_email', true );
	// If the e-mail address is empty check if the Order has a User assigned to it
	if( empty( $order->billing_email ) ) {
		// Check if a User ID has been assigned
		if( !empty( $order->user_id ) ) {
			$user = woo_ce_get_user_data( $order->user_id );
			// Check if the User is valid and e-mail assigned to User
			if( isset( $user->email ) )
				$order->billing_email = $user->email;
			unset( $user );
		}
	}
	$order->shipping_first_name = get_post_meta( $order_id, '_shipping_first_name', true );
	$order->shipping_last_name = get_post_meta( $order_id, '_shipping_last_name', true );
	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 = get_post_meta( $order_id, '_shipping_company', true );
	$order->shipping_address = '';
	$order->shipping_address_1 = get_post_meta( $order_id, '_shipping_address_1', true );
	$order->shipping_address_2 = get_post_meta( $order_id, '_shipping_address_2', true );
	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 = get_post_meta( $order_id, '_shipping_city', true );
	$order->shipping_postcode = get_post_meta( $order_id, '_shipping_postcode', true );
	$order->shipping_state = get_post_meta( $order_id, '_shipping_state', true );
	$order->shipping_country = get_post_meta( $order_id, '_shipping_country', true );
	$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 );
	$order->shipping_phone = get_post_meta( $order_id, '_shipping_phone', true );

	if( $export_type == 'order' ) {

		$order->post_id = $order->purchase_id = $order_id;
		$order->order_discount = get_post_meta( $order_id, '_cart_discount', true );
		$order->coupon_code = woo_ce_get_order_assoc_coupon( $order_id );
		if( !empty( $order->coupon_code ) ) {
			$coupon = get_page_by_title( $order->coupon_code, OBJECT, 'shop_coupon' );
			if( $coupon !== null )
				$order->coupon_description = $coupon->post_excerpt;
			unset( $coupon );
		}
		$order->order_sales_tax = get_post_meta( $order_id, '_order_tax', true );
		$order->order_shipping_tax = get_post_meta( $order_id, '_order_shipping_tax', true );
		$order->purchase_total_tax = ( $order->order_sales_tax - $order->order_shipping_tax );
		$order->order_excl_tax = ( $order->purchase_total - $order->purchase_total_tax );
		// Order Tax Percentage - Order Total - Total Tax / Total Tax
		if( !empty( $order->purchase_total_tax ) && !empty( $order->purchase_total ) )
			$order->order_tax_percentage = absint( ( $order->purchase_total - $order->purchase_total_tax ) / $order->purchase_total_tax ) . '%';
		$order->purchase_total = woo_ce_format_price( $order->purchase_total, $order->order_currency );
		$order->order_sales_tax = woo_ce_format_price( $order->order_sales_tax, $order->order_currency );
		$order->order_shipping_tax = woo_ce_format_price( $order->order_shipping_tax, $order->order_currency );
		$order->purchase_subtotal = woo_ce_format_price( $order->order_excl_tax, $order->order_currency );
		$order->order_discount = woo_ce_format_price( $order->order_discount, $order->order_currency );
		$order->order_excl_tax = woo_ce_format_price( $order->order_excl_tax, $order->order_currency );
		$order->payment_status = woo_ce_format_order_status( $order->payment_status );
		$order->payment_gateway_id = get_post_meta( $order_id, '_payment_method', true );
		$order->payment_gateway = woo_ce_format_order_payment_gateway( $order->payment_gateway_id );
		// WooCommerce 2.1 stores the shipping method in cart items, includes fallback support
		if( method_exists( $order, 'get_shipping_method' ) ) {
			$order->shipping_method_id = woo_ce_get_order_assoc_shipping_method_id( $order_id );
			$order->shipping_method = $order->get_shipping_method();
		} else {
			$order->shipping_method_id = get_post_meta( $order_id, '_shipping_method', true );
			$order->shipping_method = '';
		}
		$order->shipping_cost = woo_ce_format_price( get_post_meta( $order_id, '_order_shipping', true ), $order->order_currency );
		$order->shipping_weight = '';
		$order->order_key = get_post_meta( $order_id, '_order_key', true );
		$order->purchase_date = woo_ce_format_date( $order->order_date );
		$order->purchase_time = mysql2date( 'H:i:s', $order->order_date );
		$order->ip_address = woo_ce_format_ip_address( get_post_meta( $order_id, '_customer_ip_address', true ) );
		$order->browser_agent = get_post_meta( $order_id, '_customer_user_agent', true );
		$order->has_downloads = 0;
		$order->has_downloaded = 0;
		// Order Downloads
		if( $order_downloads = woo_ce_get_order_assoc_downloads( $order_id ) ) {
			$order->has_downloads = 1;
			foreach( $order_downloads as $order_download ) {
				// Check if any download permissions have counts against them
				if( $order_download->download_count > 0 ) {
					$order->has_downloaded = 1;
					break;
				}
			}
		}
		unset( $order_downloads, $order_download );
		$order->has_downloads = woo_ce_format_switch( $order->has_downloads );
		$order->has_downloaded = woo_ce_format_switch( $order->has_downloaded );
		$order->customer_notes = '';
		$order->order_notes = '';
		$order->total_quantity = 0;
		$order->total_order_items = 0;
		// Order Notes
		if( $order_notes = woo_ce_get_order_assoc_notes( $order_id ) ) {
			if( WOO_CD_DEBUG )
				$order->order_notes = implode( $export->category_separator, $order_notes );
			else
				$order->order_notes = implode( "\n", $order_notes );
			unset( $order_notes );
		}
		// Customer Notes
		if( $order_notes = woo_ce_get_order_assoc_notes( $order_id, 'customer_note' ) ) {
			if( WOO_CD_DEBUG )
				$order->customer_notes = implode( $export->category_separator, $order_notes );
			else
				$order->customer_notes = implode( "\n", $order_notes );
			unset( $order_notes );
		}
		if( $order->order_items = woo_ce_get_order_items( $order_id, $args['order_items_types'] ) ) {
			$order->total_order_items = count( $order->order_items );
			if( $args['order_items'] == 'combined' ) {
				$order->order_items_product_id = '';
				$order->order_items_variation_id = '';
				$order->order_items_sku = '';
				$order->order_items_name = '';
				$order->order_items_variation = '';
				$order->order_items_description = '';
				$order->order_items_excerpt = '';
				$order->order_items_tax_class = '';
				$order->order_items_quantity = '';
				$order->order_items_total = '';
				$order->order_items_subtotal = '';
				$order->order_items_rrp = '';
				$order->order_items_stock = '';
				$order->order_items_tax = '';
				$order->order_items_tax_subtotal = '';
				$order->order_items_type = '';
				$order->order_items_category = '';
				$order->order_items_tag = '';
				$order->order_items_total_sales = '';
				$order->order_items_weight = '';
				$order->order_items_total_weight = '';
				if( !empty( $order->order_items ) ) {
					foreach( $order->order_items as $order_item ) {
						if( empty( $order_item->sku ) )
							$order_item->sku = '';
						$order->order_items_product_id .= $order_item->product_id . $export->category_separator;
						$order->order_items_variation_id .= $order_item->variation_id . $export->category_separator;
						$order->order_items_sku .= $order_item->sku . $export->category_separator;
						$order->order_items_name .= $order_item->name . $export->category_separator;
						$order->order_items_variation .= $order_item->variation . $export->category_separator;
						$order->order_items_description .= woo_ce_format_description_excerpt( $order_item->description ) . $export->category_separator;
						$order->order_items_excerpt .= woo_ce_format_description_excerpt( $order_item->excerpt ) . $export->category_separator;
						$order->order_items_tax_class .= $order_item->tax_class . $export->category_separator;
						$order->total_quantity += $order_item->quantity;
						if( empty( $order_item->quantity ) && '0' != $order_item->quantity )
							$order_item->quantity = '';
						$order->order_items_quantity .= $order_item->quantity . $export->category_separator;
						$order->order_items_total .= $order_item->total . $export->category_separator;
						$order->order_items_subtotal .= $order_item->subtotal . $export->category_separator;
						$order->order_items_rrp .= $order_item->rrp . $export->category_separator;
						$order->order_items_stock .= $order_item->stock . $export->category_separator;
						$order->order_items_tax .= $order_item->tax . $export->category_separator;
						$order->order_items_tax_subtotal .= $order_item->tax_subtotal . $export->category_separator;
						$order->order_items_type .= $order_item->type . $export->category_separator;
						$order->order_items_category .= $order_item->category . $export->category_separator;
						$order->order_items_tag .= $order_item->tag . $export->category_separator;
						$order->order_items_total_sales .= $order_item->total_sales . $export->category_separator;
						$order->order_items_weight .= $order_item->weight . $export->category_separator;
						$order->order_items_total_weight .= $order_item->total_weight . $export->category_separator;
						// Add Order Item weight to Shipping Weight
						if( $order_item->total_weight != '' )
							$order->shipping_weight = $order->shipping_weight + $order_item->total_weight;
					}
					$order->order_items_product_id = substr( $order->order_items_product_id, 0, -1 );
					$order->order_items_variation_id = substr( $order->order_items_variation_id, 0, -1 );
					$order->order_items_sku = substr( $order->order_items_sku, 0, -1 );
					$order->order_items_name = substr( $order->order_items_name, 0, -1 );
					$order->order_items_variation = substr( $order->order_items_variation, 0, -1 );
					$order->order_items_description = substr( $order->order_items_description, 0, -1 );
					$order->order_items_excerpt = substr( $order->order_items_excerpt, 0, -1 );
					$order->order_items_tax_class = substr( $order->order_items_tax_class, 0, -1 );
					$order->order_items_quantity = substr( $order->order_items_quantity, 0, -1 );
					$order->order_items_total = substr( $order->order_items_total, 0, -1 );
					$order->order_items_subtotal = substr( $order->order_items_subtotal, 0, -1 );
					$order->order_items_rrp = substr( $order->order_items_rrp, 0, -1 );
					$order->order_items_stock = substr( $order->order_items_stock, 0, -1 );
					$order->order_items_tax = substr( $order_item->tax, 0, -1 );
					$order->order_items_tax_subtotal = substr( $order_item->tax_subtotal, 0, -1 );
					$order->order_items_type = substr( $order->order_items_type, 0, -1 );
					$order->order_items_category = substr( $order->order_items_category, 0, -1 );
					$order->order_items_tag = substr( $order->order_items_tag, 0, -1 );
					$order->order_items_total_sales = substr( $order->order_items_total_sales, 0, -1 );
					$order->order_items_weight = substr( $order->order_items_weight, 0, -1 );
					$order->order_items_total_weight = substr( $order->order_items_total_weight, 0, -1 );
				}
				$order = apply_filters( 'woo_ce_order_items_combined', $order );
			} else if( $args['order_items'] == 'unique' ) {
				if( !empty( $order->order_items ) ) {
					$i = 1;
					foreach( $order->order_items as $order_item ) {
						$order->{sprintf( 'order_item_%d_product_id', $i )} = $order_item->product_id;
						$order->{sprintf( 'order_item_%d_variation_id', $i )} = $order_item->variation_id;
						$order->{sprintf( 'order_item_%d_sku', $i )} = ( empty( $order_item->sku ) == false ? $order_item->sku : '' );
						$order->{sprintf( 'order_item_%d_name', $i )} = $order_item->name;
						$order->{sprintf( 'order_item_%d_variation', $i )} = $order_item->variation;
						$order->{sprintf( 'order_item_%d_description', $i )} = $order_item->description;
						$order->{sprintf( 'order_item_%d_excerpt', $i )} = $order_item->excerpt;
						$order->{sprintf( 'order_item_%d_tax_class', $i )} = $order_item->tax_class;
						$order->total_quantity += $order_item->quantity;
						if( empty( $order_item->quantity ) && '0' != $order_item->quantity )
							$order_item->quantity = '';
						$order->{sprintf( 'order_item_%d_quantity', $i )} = $order_item->quantity;
						$order->{sprintf( 'order_item_%d_total', $i )} = $order_item->total;
						$order->{sprintf( 'order_item_%d_subtotal', $i )} = $order_item->subtotal;
						$order->{sprintf( 'order_item_%d_rrp', $i )} = $order_item->rrp;
						$order->{sprintf( 'order_item_%d_stock', $i )} = $order_item->stock;
						$order->{sprintf( 'order_item_%d_tax', $i )} = $order_item->tax;
						$order->{sprintf( 'order_item_%d_tax_subtotal', $i )} = $order_item->tax_subtotal;
						$order->{sprintf( 'order_item_%d_type', $i )} = $order_item->type;
						$order->{sprintf( 'order_item_%d_category', $i )} = $order_item->category;
						$order->{sprintf( 'order_item_%d_tag', $i )} = $order_item->tag;
						$order->{sprintf( 'order_item_%d_total_sales', $i )} = $order_item->total_sales;
						$order->{sprintf( 'order_item_%d_weight', $i )} = $order_item->weight;
						$order->{sprintf( 'order_item_%d_total_weight', $i )} = $order_item->total_weight;
						// Add Order Item weight to Shipping Weight
						if( $order_item->total_weight != '' )
							$order->shipping_weight = $order->shipping_weight + $order_item->total_weight;
						$order = apply_filters( 'woo_ce_order_items_unique', $order, $i, $order_item );
						$i++;
					}
				}
			}
		}

		// Custom Order fields
		$custom_orders = woo_ce_get_option( 'custom_orders', '' );
		if( !empty( $custom_orders ) ) {
			foreach( $custom_orders as $custom_order ) {
				if( !empty( $custom_order ) ) {
					$order->{$custom_order} = woo_ce_format_custom_meta( get_post_meta( $order_id, $custom_order, true ) );
				}
			}
		}

	} else if( $export_type = 'customer' ) {

		// Check if the Order has a User assigned to it
		if( !empty( $order->user_id ) ) {

			// Load up the User data as other Plugins will use it too
			$user = woo_ce_get_user_data( $order->user_id );

			// WooCommerce Follow-Up Emails - http://www.woothemes.com/products/follow-up-emails/
			if( class_exists( 'FollowUpEmails' ) ) {

				global $wpdb;

				if( isset( $user->email ) ) {
					$followup_optout_sql = $wpdb->prepare( "SELECT `id` FROM `" . $wpdb->prefix . "followup_email_excludes` WHERE `email` = %s LIMIT 1", $user->email );
					$order->followup_optout = $wpdb->get_var( $followup_optout_sql );
				}

			}

			// Custom User fields
			$custom_users = woo_ce_get_option( 'custom_users', '' );
			if( !empty( $custom_users ) ) {
				foreach( $custom_users as $custom_user ) {
					if( !empty( $custom_user ) && !isset( $order->{$custom_user} ) ) {
						$order->{$custom_user} = woo_ce_format_custom_meta( get_user_meta( $order->user_id, $custom_user, true ) );
					}
				}
			}
			unset( $custom_users, $custom_user );

			// Clean up
			unset( $user );

		}

		// Custom Customer fields
		$custom_customers = woo_ce_get_option( 'custom_customers', '' );
		if( !empty( $custom_customers ) ) {
			foreach( $custom_customers as $custom_customer ) {
				if( !empty( $custom_customer ) )
					$order->{$custom_customer} = esc_attr( get_user_meta( $order->user_id, $custom_customer, true ) );
			}
		}

	}

	$order = apply_filters( 'woo_ce_order', $order, $order_id );

	// Trim back the Order just to requested export fields
	if( !empty( $fields ) ) {
		$fields[] = 'id';
		if( $args['order_items'] == 'individual' )
			$fields[] = 'order_items';
		if( !empty( $order ) ) {
			foreach( $order as $key => $data ) {
				if( !in_array( $key, $fields ) )
					unset( $order->$key );
			}
		}
	}

	return $order;

}
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
function woo_ce_get_coupon_data( $coupon_id = 0, $args = array() ) {

	global $export;

	$coupon = get_post( $coupon_id );

	$coupon->coupon_code = $coupon->post_title;
	$coupon->discount_type = woo_ce_format_discount_type( get_post_meta( $coupon->ID, 'discount_type', true ) );
	$coupon->coupon_description = $coupon->post_excerpt;
	$coupon->coupon_amount = get_post_meta( $coupon->ID, 'coupon_amount', true );
	$coupon->individual_use = woo_ce_format_switch( get_post_meta( $coupon->ID, 'individual_use', true ) );
	$coupon->apply_before_tax = woo_ce_format_switch( get_post_meta( $coupon->ID, 'apply_before_tax', true ) );
	$coupon->exclude_sale_items = woo_ce_format_switch( get_post_meta( $coupon->ID, 'exclude_sale_items', true ) );
	$coupon->minimum_amount = get_post_meta( $coupon->ID, 'minimum_amount', true );
	$coupon->product_ids = woo_ce_convert_product_ids( get_post_meta( $coupon->ID, 'product_ids', true ) );
	$coupon->exclude_product_ids = woo_ce_convert_product_ids( get_post_meta( $coupon->ID, 'exclude_product_ids', true ) );
	$coupon->product_categories = woo_ce_convert_product_ids( get_post_meta( $coupon->ID, 'product_categories', true ) );
	$coupon->exclude_product_categories = woo_ce_convert_product_ids( get_post_meta( $coupon->ID, 'exclude_product_categories', true ) );
	$coupon->customer_email = woo_ce_convert_product_ids( get_post_meta( $coupon->ID, 'customer_email', true ) );
	$coupon->usage_limit = get_post_meta( $coupon->ID, 'usage_limit', true );
	$coupon->expiry_date = woo_ce_format_date( get_post_meta( $coupon->ID, 'expiry_date', true ) );
	$coupon->usage_count = get_post_meta( $coupon->ID, 'usage_count', true );
	$coupon->usage_cost = woo_ce_get_coupon_usage_cost( $coupon->coupon_code );
	$coupon->used_by = woo_ce_convert_product_ids( get_post_meta( $coupon->ID, '_used_by', false ) );
	return $coupon;

}
Ejemplo n.º 6
0
function woo_ce_get_product_data( $product_id = 0, $args = array(), $fields = array() ) {

	// Get Product defaults
	$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;

	$product = get_post( $product_id );
	$_product = ( function_exists( 'wc_get_product' ) ? wc_get_product( $product_id ) : false );

	$product->parent_id = '';
	$product->parent_sku = '';
	if( $product->post_type == 'product_variation' ) {
		// Assign Parent ID for Variants then check if Parent exists
		if( $product->parent_id = $product->post_parent )
			$product->parent_sku = get_post_meta( $product->post_parent, '_sku', true );
		else
			$product->parent_id = '';
	}
	$product->product_id = $product_id;
	$product->sku = get_post_meta( $product_id, '_sku', true );
	$product->name = get_the_title( $product_id );
	if( $product->post_type <> 'product_variation' )
		$product->permalink = get_permalink( $product_id );
	$product->product_url = ( method_exists( $_product, 'get_permalink' ) ? $_product->get_permalink() : get_permalink( $product_id ) );
	$product->slug = $product->post_name;
	$product->description = woo_ce_format_description_excerpt( $product->post_content );
	$product->excerpt = woo_ce_format_description_excerpt( $product->post_excerpt );
	$product->price = get_post_meta( $product_id, '_regular_price', true );
	$product->sale_price = get_post_meta( $product_id, '_sale_price', true );

	// Check if we're dealing with a Variable Product Type
	$term_taxonomy = 'product_type';
	if( has_term( 'variable', $term_taxonomy, $product_id ) )
		$product->price = get_post_meta( $product_id, '_price', true );

	if( isset( $product->price ) && $product->price != '' )
		$product->price = woo_ce_format_price( $product->price );
	if( isset( $product->sale_price ) && $product->sale_price != '' )
		$product->sale_price = woo_ce_format_price( $product->sale_price );
	$product->sale_price_dates_from = woo_ce_format_product_sale_price_dates( get_post_meta( $product_id, '_sale_price_dates_from', true ) );
	$product->sale_price_dates_to = woo_ce_format_product_sale_price_dates( get_post_meta( $product_id, '_sale_price_dates_to', true ) );
	$product->post_date = woo_ce_format_date( $product->post_date );
	$product->post_modified = woo_ce_format_date( $product->post_modified );
	$product->type = woo_ce_get_product_assoc_type( $product_id );
	if( $product->post_type == 'product_variation' ) {
		// Override the Product Type for Variations
		$product->type = __( 'Variation', 'woo_ce' );
		// Override the Description and Excerpt if Variation Formatting is enabled
		if( woo_ce_get_option( 'variation_formatting', 0 ) ) {
			$parent = get_post( $product->parent_id );
			$product->description = $parent->post_content;
			$product->excerpt = $parent->post_excerpt;
			unset( $parent );
		}
	}
	$product->visibility = woo_ce_format_product_visibility( get_post_meta( $product_id, '_visibility', true ) );
	$product->featured = woo_ce_format_switch( get_post_meta( $product_id, '_featured', true ) );
	$product->virtual = woo_ce_format_switch( get_post_meta( $product_id, '_virtual', true ) );
	$product->downloadable = woo_ce_format_switch( get_post_meta( $product_id, '_downloadable', true ) );
	$product->weight = get_post_meta( $product_id, '_weight', true );
	$product->weight_unit = ( $product->weight != '' ? $weight_unit : '' );
	$product->height = get_post_meta( $product_id, '_height', true );
	$product->height_unit = ( $product->height != '' ? $height_unit : '' );
	$product->width = get_post_meta( $product_id, '_width', true );
	$product->width_unit = ( $product->width != '' ? $width_unit : '' );
	$product->length = get_post_meta( $product_id, '_length', true );
	$product->length_unit = ( $product->length != '' ? $length_unit : '' );
	$product->category = woo_ce_get_product_assoc_categories( $product_id, $product->parent_id );
	$product->tag = woo_ce_get_product_assoc_tags( $product_id );
	$product->manage_stock = woo_ce_format_switch( get_post_meta( $product_id, '_manage_stock', true ) );
	$product->allow_backorders = woo_ce_format_switch( get_post_meta( $product_id, '_backorders', true ) );
	$product->sold_individually = woo_ce_format_switch( get_post_meta( $product_id, '_sold_individually', true ) );
	$product->total_sales = get_post_meta( $product_id, 'total_sales', true );
	$product->upsell_ids = woo_ce_get_product_assoc_upsell_ids( $product_id );
	$product->crosssell_ids = woo_ce_get_product_assoc_crosssell_ids( $product_id );
	$product->quantity = get_post_meta( $product_id, '_stock', true );
	$product->quantity = ( function_exists( 'wc_stock_amount' ) ? wc_stock_amount( $product->quantity ) : $product->quantity );
	$product->stock_status = woo_ce_format_product_stock_status( get_post_meta( $product_id, '_stock_status', true ), $product->quantity );
	$product->image = woo_ce_get_product_assoc_featured_image( $product_id, $product->parent_id );
	$product->image_thumbnail = woo_ce_get_product_assoc_featured_image( $product_id, $product->parent_id, 'thumbnail' );
	$product->product_gallery = woo_ce_get_product_assoc_product_gallery( $product_id );
	$product->product_gallery_thumbnail = woo_ce_get_product_assoc_product_gallery( $product_id, 'thumbnail' );
	$product->tax_status = woo_ce_format_product_tax_status( get_post_meta( $product_id, '_tax_status', true ) );
	$product->tax_class = woo_ce_format_product_tax_class( get_post_meta( $product_id, '_tax_class', true ) );
	$product->shipping_class = woo_ce_get_product_assoc_shipping_class( $product_id );
	$product->external_url = get_post_meta( $product_id, '_product_url', true );
	$product->button_text = get_post_meta( $product_id, '_button_text', true );
	$product->download_file_path = woo_ce_get_product_assoc_download_files( $product_id, 'url' );
	$product->download_file_name = woo_ce_get_product_assoc_download_files( $product_id, 'name' );
	$product->download_limit = get_post_meta( $product_id, '_download_limit', true );
	$product->download_expiry = get_post_meta( $product_id, '_download_expiry', true );
	$product->download_type = woo_ce_format_product_download_type( get_post_meta( $product_id, '_download_type', true ) );
	$product->purchase_note = get_post_meta( $product_id, '_purchase_note', true );
	$product->product_status = woo_ce_format_post_status( $product->post_status );
	$product->enable_reviews = woo_ce_format_comment_status( $product->comment_status );
	$product->menu_order = $product->menu_order;

	// Attributes
	if( $attributes = woo_ce_get_product_attributes() ) {
		// Scan for global Attributes first
		if( $product->post_type == 'product_variation' ) {
			// We're dealing with a single Variation, strap yourself in.
			foreach( $attributes as $attribute ) {
				$attribute_value = get_post_meta( $product_id, sprintf( 'attribute_pa_%s', $attribute->attribute_name ), true );
				if( !empty( $attribute_value ) ) {
					$term_id = term_exists( $attribute_value, sprintf( 'pa_%s', $attribute->attribute_name ) );
					if( $term_id !== 0 && $term_id !== null && !is_wp_error( $term_id ) ) {
						$term = get_term( $term_id['term_id'], sprintf( 'pa_%s', $attribute->attribute_name ) );
						$attribute_value = $term->name;
						unset( $term );
					}
					unset( $term_id );
				}
				$product->{'attribute_' . $attribute->attribute_name} = $attribute_value;
				unset( $attribute_value );
			}
		} else {
			// Either the Variation Parent or a Simple Product, scan for global and custom Attributes
			$product->attributes = maybe_unserialize( get_post_meta( $product_id, '_product_attributes', true ) );
			if( !empty( $product->attributes ) ) {
				$default_attributes = maybe_unserialize( get_post_meta( $product_id, '_default_attributes', true ) );
				$product->default_attributes = '';
				// Check for taxonomy-based attributes
				foreach( $attributes as $attribute ) {
					if( !empty( $default_attributes ) && is_array( $default_attributes ) ) {
						if( array_key_exists( 'pa_' . $attribute->attribute_name, $default_attributes ) )
							$product->default_attributes .= $attribute->attribute_label . ': ' . $default_attributes['pa_' . $attribute->attribute_name] . "|";
					}
					if( isset( $product->attributes['pa_' . $attribute->attribute_name] ) )
						$product->{'attribute_' . $attribute->attribute_name} = woo_ce_get_product_assoc_attributes( $product_id, $product->attributes['pa_' . $attribute->attribute_name], 'product' );
					else
						$product->{'attribute_' . $attribute->attribute_name} = woo_ce_get_product_assoc_attributes( $product_id, $attribute, 'global' );
				}
				// Check for per-Product attributes (custom)
				foreach( $product->attributes as $key => $attribute ) {
					if( $attribute['is_taxonomy'] == 0 ) {
						if( !isset( $product->{'attribute_' . $key} ) )
							$product->{'attribute_' . $key} = $attribute['value'];
					}
				}
				if( !empty( $product->default_attributes ) )
					$product->default_attributes = substr( $product->default_attributes, 0, -1 );
			}
		}
	}

	// Allow Plugin/Theme authors to add support for additional Product columns
	$product = apply_filters( 'woo_ce_product_item', $product, $product_id );

	// Trim back the Product just to requested export fields
	if( !empty( $fields ) ) {
		$fields = array_merge( $fields, array( 'id', 'ID', 'post_parent', 'filter' ) );
		if( !empty( $product ) ) {
			foreach( $product as $key => $data ) {
				if( !in_array( $key, $fields ) )
					unset( $product->$key );
			}
		}
	}

	return $product;

}