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_format_sale_price_dates($sale_date = '') { $output = $sale_date; if ($sale_date) { $output = woo_ce_format_date(date('Y-m-d H:i:s', $sale_date)); } return $output; }
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; }
function woo_ce_extend_order_items_individual( $order, $order_item ) { global $export; // Product Add-ons - http://www.woothemes.com/ if( $product_addons = woo_ce_get_product_addons() ) { foreach( $product_addons as $product_addon ) { if( isset( $order_item->product_addons[$product_addon->post_name] ) ) $order->{'order_items_product_addon_' . $product_addon->post_name} = $order_item->product_addons[$product_addon->post_name]; } } // Gravity Forms - http://woothemes.com/woocommerce if( $gf_fields = woo_ce_get_gravity_form_fields() ) { if( $order->order_items ) { $order->order_items_gf_form_id = $order_item->gf_form_id; $order->order_items_gf_form_label = $order_item->gf_form_label; $meta_type = 'order_item'; foreach( $gf_fields as $gf_field ) { // Check that we only fill export fields for forms that are actually filled if( $gf_field['formId'] == $order_item->gf_form_id ) $order->{sprintf( 'order_items_gf_%d_%s', $gf_field['formId'], $gf_field['id'] )} = get_metadata( $meta_type, $order_item->id, $gf_field['label'], true ); } unset( $gf_fields, $gf_field ); } } // WooCommerce Checkout Add-Ons - http://www.skyverge.com/product/woocommerce-checkout-add-ons/ if( function_exists( 'init_woocommerce_checkout_add_ons' ) ) { $order->order_items_checkout_addon_id = $order_item->checkout_addon_id; $order->order_items_checkout_addon_label = $order_item->checkout_addon_label; $order->order_items_checkout_addon_value = $order_item->checkout_addon_value; } // WooCommerce Brands Addon - http://woothemes.com/woocommerce/ // WooCommerce Brands - http://proword.net/Woocommerce_Brands/ if( class_exists( 'WC_Brands' ) || class_exists( 'woo_brands' ) || taxonomy_exists( apply_filters( 'woo_ce_brand_term_taxonomy', 'product_brand' ) ) ) $order->order_items_brand = $order_item->brand; // Product Vendors - http://www.woothemes.com/products/product-vendors/ if( class_exists( 'WooCommerce_Product_Vendors' ) ) $order->order_items_vendor = $order_item->vendor; // Cost of Goods - http://www.skyverge.com/product/woocommerce-cost-of-goods-tracking/ if( class_exists( 'WC_COG' ) ) { $order->order_items_cost_of_goods = $order_item->cost_of_goods; $order->order_items_total_cost_of_goods = $order_item->total_cost_of_goods; } // WooCommerce MSRP Pricing - http://woothemes.com/woocommerce/ if( function_exists( 'woocommerce_msrp_activate' ) ) $order->order_items_msrp = $order_item->msrp; // Local Pickup Plus - http://www.woothemes.com/products/local-pickup-plus/ if( class_exists( 'WC_Local_Pickup_Plus' ) ) { $meta_type = 'order_item'; $pickup_location = get_metadata( $meta_type, $order_item->id, 'Pickup Location', true ); if( !empty( $pickup_location ) ) $order->order_items_pickup_location = get_metadata( $meta_type, $order_item->id, 'Pickup Location', true ); unset( $pickup_location ); } // WooCommerce Bookings - http://www.woothemes.com/products/woocommerce-bookings/ if( class_exists( 'WC_Bookings' ) ) { $booking_id = woo_ce_get_order_assoc_booking_id( $order->id ); if( !empty( $booking_id ) ) { $order->order_items_booking_id = $booking_id; $booking_start_date = get_post_meta( $booking_id, '_booking_start', true ); if( !empty( $booking_start_date ) ) $order->order_items_booking_start_date = woo_ce_format_date( date( 'Y-m-d', strtotime( $booking_start_date ) ) ); unset( $booking_start_date ); $booking_end_date = get_post_meta( $booking_id, '_booking_end', true ); if( !empty( $booking_end_date ) ) $order->order_items_booking_end_date = woo_ce_format_date( date( 'Y-m-d', strtotime( $booking_end_date ) ) ); unset( $booking_end_date ); } unset( $booking_id ); $meta_type = 'order_item'; $booking_date = get_metadata( $meta_type, $order_item->id, 'Booking Date', true ); if( !empty( $booking_date ) ) $order->order_items_booking_date = get_metadata( $meta_type, $order_item->id, 'Booking Date', true ); unset( $booking_date ); $booking_type = get_metadata( $meta_type, $order_item->id, 'Booking Type', true ); if( !empty( $booking_type ) ) $order->order_items_booking_type = get_metadata( $meta_type, $order_item->id, 'Booking Type', true ); unset( $booking_type ); } // WooCommerce TM Extra Product Options - http://codecanyon.net/item/woocommerce-extra-product-options/7908619 if( class_exists( 'TM_Extra_Product_Options' ) ) { if( $tm_fields = woo_ce_get_extra_product_option_fields() ) { foreach( $tm_fields as $tm_field ) $order->{sprintf( 'order_items_tm_%s', sanitize_key( $tm_field['name'] ) )} = $order_item->{sprintf( 'tm_%s', sanitize_key( $tm_field['name'] ) )}; } unset( $tm_fields, $tm_field ); } // Attributes if( $attributes = woo_ce_get_product_attributes() ) { foreach( $attributes as $attribute ) { if( isset( $order_item->{'attribute_' . sanitize_key( $attribute->attribute_name )} ) ) $order->{'order_items_attribute_' . sanitize_key( $attribute->attribute_name )} = $order_item->{'attribute_' . sanitize_key( $attribute->attribute_name )}; } unset( $attributes, $attribute ); } // WooCommerce Ship to Multiple Addresses - http://woothemes.com/woocommerce if( class_exists( 'WC_Ship_Multiple' ) ) { $shipping_packages = get_post_meta( $order->ID, '_wcms_packages', true ); if( !empty( $shipping_packages ) ) { // Override the Shipping address $order->shipping_first_name = ''; $order->shipping_last_name = ''; if( empty( $order->shipping_first_name ) && empty( $order->shipping_first_name ) ) $order->shipping_full_name = ''; else $order->shipping_full_name = ''; $order->shipping_company = ''; $order->shipping_address = ''; $order->shipping_address_1 = ''; $order->shipping_address_2 = ''; $order->shipping_city = ''; $order->shipping_postcode = ''; $order->shipping_state = ''; $order->shipping_country = ''; $order->shipping_state_full = ''; $order->shipping_country_full = ''; // Override the shipping method foreach( $shipping_packages as $shipping_package ) { $contents = $shipping_package['contents']; if( !empty( $contents ) ) { foreach( $contents as $content ) { if( $content['product_id'] == $order_item->product_id ) { $order->shipping_first_name = $shipping_package['full_address']['first_name']; $order->shipping_last_name = $shipping_package['full_address']['last_name']; if( empty( $order->shipping_first_name ) && empty( $order->shipping_last_name ) ) $order->shipping_full_name = ''; else $order->shipping_full_name = $order->shipping_first_name . ' ' . $order->shipping_last_name; $order->shipping_company = $shipping_package['full_address']['company']; $order->shipping_address = ''; $order->shipping_address_1 = $shipping_package['full_address']['address_1']; $order->shipping_address_2 = $shipping_package['full_address']['address_2']; if( !empty( $order->billing_address_2 ) ) $order->shipping_address = sprintf( apply_filters( 'woo_ce_get_order_data_shipping_address', '%s %s' ), $order->shipping_address_1, $order->shipping_address_2 ); else $order->shipping_address = $order->shipping_address_1; $order->shipping_city = $shipping_package['full_address']['city']; $order->shipping_postcode = $shipping_package['full_address']['postcode']; $order->shipping_state = $shipping_package['full_address']['state']; $order->shipping_country = $shipping_package['full_address']['country']; $order->shipping_state_full = woo_ce_expand_state_name( $order->shipping_country, $order->shipping_state ); $order->shipping_country_full = woo_ce_expand_country_name( $order->shipping_country ); break; break; } } } unset( $contents ); } } unset( $shipping_packages ); } // Custom Order Items fields $custom_order_items = woo_ce_get_option( 'custom_order_items', '' ); if( !empty( $custom_order_items ) ) { foreach( $custom_order_items as $custom_order_item ) { if( !empty( $custom_order_item ) ) $order->{'order_items_' . $custom_order_item} = $order_item->{$custom_order_item}; } } unset( $custom_order_items, $custom_order_item ); // Custom Product fields $custom_products = woo_ce_get_option( 'custom_products', '' ); if( !empty( $custom_products ) ) { foreach( $custom_products as $custom_product ) { if( !empty( $custom_product ) ) $order->{'order_items_' . $custom_product} = $order_item->{$custom_product}; } } unset( $custom_products, $custom_product ); return $order; }
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; }
function woo_ce_get_commission_data( $commission_id = 0, $args = array() ) { global $export; $commission = get_post( $commission_id ); $commission->title = $commission->post_title; $commission->product_id = get_post_meta( $commission->ID, '_commission_product', true ); $commission->product_name = get_the_title( $commission->product_id ); $commission->product_sku = get_post_meta( $commission->product_id, '_sku', true ); $commission->product_vendor_id = get_post_meta( $commission->ID, '_commission_vendor', true ); $product_vendor = woo_ce_get_product_vendor_data( $commission->product_vendor_id ); $commission->product_vendor_name = ( isset( $product_vendor->title ) ? $product_vendor->title : '' ); unset( $product_vendor ); $commission->commission_amount = get_post_meta( $commission->ID, '_commission_amount', true ); // Check that a valid price has been provided if( isset( $commission->commission_amount ) && $commission->commission_amount != '' && function_exists( 'wc_format_localized_price' ) ) $commission->commission_amount = woo_ce_format_price( $commission->commission_amount ); $commission->paid_status = woo_ce_format_commission_paid_status( get_post_meta( $commission->ID, '_paid_status', true ) ); $commission->post_date = woo_ce_format_date( $commission->post_date ); $commission->post_status = woo_ce_format_post_status ( $commission->post_status ); return $commission; }
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']; } 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, 'numberposts' => $limit_volume, 'orderby' => $orderby, 'order' => $order, 'offset' => $offset, 'post_status' => woo_ce_post_statuses(), 'cache_results' => false); if ($product_categories) { $term_taxonomy = 'product_cat'; $args['tax_query'] = array(array('taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_categories)); } 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)) { $args['post_type'] = 'product_variation'; } else { $args['tax_query'] = array(array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $product_type)); } } if ($products = get_posts($args)) { $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') { // Assign Parent ID for Variants then check if Parent exists if ($products[$key]->parent_id = $product->post_parent) { if (!get_post($products[$key]->parent_id)) { unset($products[$key]); continue; } $products[$key]->parent_sku = get_post_meta($product->post_parent, '_sku', true); } else { $products[$key]->parent_id = ''; } } $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 = $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 = $product->post_excerpt; $products[$key]->post_date = woo_ce_format_date($product->post_date); $products[$key]->post_modified = woo_ce_format_date($product->post_modified); $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]->parent_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]->quantity); $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_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; } }