function woo_ce_tab_template($tab = '') { if (!$tab) { $tab = 'overview'; } // Store Exporter Deluxe $woo_cd_url = 'http://www.visser.com.au/woocommerce/plugins/exporter-deluxe/'; $woo_cd_link = sprintf('<a href="%s" target="_blank">' . __('Store Exporter Deluxe', 'woo_ce') . '</a>', $woo_cd_url); $troubleshooting_url = 'http://www.visser.com.au/documentation/store-exporter-deluxe/'; switch ($tab) { case 'overview': $skip_overview = woo_ce_get_option('skip_overview', false); break; case 'export': $export_type = sanitize_text_field(isset($_POST['dataset']) ? $_POST['dataset'] : woo_ce_get_option('last_export', 'product')); $types = array_keys(woo_ce_return_export_types()); // Check if the default export type exists if (!in_array($export_type, $types)) { $export_type = 'product'; } $products = woo_ce_return_count('product'); $categories = woo_ce_return_count('category'); $tags = woo_ce_return_count('tag'); $brands = '999'; $orders = '999'; $customers = '999'; $users = woo_ce_return_count('user'); $coupons = '999'; $attributes = '999'; $subscriptions = '999'; $product_vendors = '999'; $commissions = '999'; $shipping_classes = '999'; add_action('woo_ce_export_options', 'woo_ce_export_options_export_format'); if ($product_fields = woo_ce_get_product_fields()) { foreach ($product_fields as $key => $product_field) { $product_fields[$key]['disabled'] = isset($product_field['disabled']) ? $product_field['disabled'] : 0; } add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_category'); add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_tag'); add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_brand'); add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_vendor'); add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_status'); add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_type'); add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_stock_status'); add_action('woo_ce_export_product_options_after_table', 'woo_ce_product_sorting'); add_action('woo_ce_export_options', 'woo_ce_products_upsells_formatting'); add_action('woo_ce_export_options', 'woo_ce_products_crosssells_formatting'); add_action('woo_ce_export_options', 'woo_ce_export_options_gallery_format'); add_action('woo_ce_export_after_form', 'woo_ce_products_custom_fields'); } if ($category_fields = woo_ce_get_category_fields()) { foreach ($category_fields as $key => $category_field) { $category_fields[$key]['disabled'] = isset($category_field['disabled']) ? $category_field['disabled'] : 0; } add_action('woo_ce_export_category_options_after_table', 'woo_ce_category_sorting'); } if ($tag_fields = woo_ce_get_tag_fields()) { foreach ($tag_fields as $key => $tag_field) { $tag_fields[$key]['disabled'] = isset($tag_field['disabled']) ? $tag_field['disabled'] : 0; } add_action('woo_ce_export_tag_options_after_table', 'woo_ce_tag_sorting'); } if ($brand_fields = woo_ce_get_brand_fields()) { foreach ($brand_fields as $key => $brand_field) { $brand_fields[$key]['disabled'] = isset($brand_field['disabled']) ? $brand_field['disabled'] : 0; } add_action('woo_ce_export_brand_options_before_table', 'woo_ce_brand_sorting'); } if ($order_fields = woo_ce_get_order_fields()) { add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_date'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_status'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_customer'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_billing_country'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_shipping_country'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_user_role'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_coupon'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_product'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_product_category'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_product_tag'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_product_brand'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_order_id'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_payment_gateway'); add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_shipping_method'); add_action('woo_ce_export_order_options_after_table', 'woo_ce_order_sorting'); add_action('woo_ce_export_options', 'woo_ce_orders_items_formatting'); add_action('woo_ce_export_options', 'woo_ce_orders_max_order_items'); add_action('woo_ce_export_options', 'woo_ce_orders_items_types'); add_action('woo_ce_export_after_form', 'woo_ce_orders_custom_fields'); } if ($customer_fields = woo_ce_get_customer_fields()) { add_action('woo_ce_export_customer_options_before_table', 'woo_ce_customers_filter_by_status'); add_action('woo_ce_export_customer_options_before_table', 'woo_ce_customers_filter_by_user_role'); add_action('woo_ce_export_after_form', 'woo_ce_customers_custom_fields'); } if ($user_fields = woo_ce_get_user_fields()) { foreach ($user_fields as $key => $user_field) { $user_fields[$key]['disabled'] = isset($user_field['disabled']) ? $user_field['disabled'] : 0; } add_action('woo_ce_export_user_options_after_table', 'woo_ce_user_sorting'); add_action('woo_ce_export_after_form', 'woo_ce_users_custom_fields'); } if ($coupon_fields = woo_ce_get_coupon_fields()) { add_action('woo_ce_export_coupon_options_before_table', 'woo_ce_coupon_sorting'); } if ($subscription_fields = woo_ce_get_subscription_fields()) { add_action('woo_ce_export_subscription_options_before_table', 'woo_ce_subscriptions_filter_by_subscription_status'); add_action('woo_ce_export_subscription_options_before_table', 'woo_ce_subscriptions_filter_by_subscription_product'); } $product_vendor_fields = woo_ce_get_product_vendor_fields(); if ($commission_fields = woo_ce_get_commission_fields()) { add_action('woo_ce_export_commission_options_before_table', 'woo_ce_commissions_filter_by_date'); add_action('woo_ce_export_commission_options_before_table', 'woo_ce_commissions_filter_by_product_vendor'); add_action('woo_ce_export_commission_options_before_table', 'woo_ce_commissions_filter_by_commission_status'); add_action('woo_ce_export_commission_options_before_table', 'woo_ce_commission_sorting'); } if ($shipping_class_fields = woo_ce_get_shipping_class_fields()) { add_action('woo_ce_export_shipping_class_options_after_table', 'woo_ce_shipping_class_sorting'); } $attribute_fields = false; // Export modules $modules = woo_ce_modules_list(); // Export options $limit_volume = woo_ce_get_option('limit_volume'); $offset = woo_ce_get_option('offset'); break; case 'fields': $export_type = isset($_GET['type']) ? sanitize_text_field($_GET['type']) : ''; $types = array_keys(woo_ce_return_export_types()); $fields = array(); if (in_array($export_type, $types)) { if (has_filter('woo_ce_' . $export_type . '_fields', 'woo_ce_override_' . $export_type . '_field_labels')) { remove_filter('woo_ce_' . $export_type . '_fields', 'woo_ce_override_' . $export_type . '_field_labels', 11); } if (function_exists(sprintf('woo_ce_get_%s_fields', $export_type))) { $fields = call_user_func('woo_ce_get_' . $export_type . '_fields'); } $labels = woo_ce_get_option($export_type . '_labels', array()); } break; case 'archive': if (isset($_GET['deleted'])) { $message = __('Archived export has been deleted.', 'woo_ce'); woo_ce_admin_notice($message); } if ($files = woo_ce_get_archive_files()) { foreach ($files as $key => $file) { $files[$key] = woo_ce_get_archive_file($file); } } break; case 'settings': $export_filename = woo_ce_get_option('export_filename', ''); // Default export filename if (empty($export_filename)) { $export_filename = 'woo-export_%dataset%-%date%.csv'; } $delete_file = woo_ce_get_option('delete_file', 0); $timeout = woo_ce_get_option('timeout', 0); $encoding = woo_ce_get_option('encoding', 'UTF-8'); $bom = woo_ce_get_option('bom', 1); $delimiter = woo_ce_get_option('delimiter', ','); $category_separator = woo_ce_get_option('category_separator', '|'); $escape_formatting = woo_ce_get_option('escape_formatting', 'all'); $date_format = woo_ce_get_option('date_format', 'd/m/Y'); if ($date_format == 1 || $date_format == '') { $date_format = 'd/m/Y'; } $file_encodings = function_exists('mb_list_encodings') ? mb_list_encodings() : false; add_action('woo_ce_export_settings_top', 'woo_ce_export_settings_quicklinks'); add_action('woo_ce_export_settings_after', 'woo_ce_export_settings_csv'); add_action('woo_ce_export_settings_after', 'woo_ce_export_settings_cron'); break; case 'tools': // Product Importer Deluxe $woo_pd_url = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/'; $woo_pd_target = ' target="_blank"'; if (function_exists('woo_pd_init')) { $woo_pd_url = add_query_arg(array('page' => 'woo_pd', 'tab' => null)); $woo_pd_target = false; } // Store Toolkit $woo_st_url = 'http://www.visser.com.au/woocommerce/plugins/store-toolkit/'; $woo_st_target = ' target="_blank"'; if (function_exists('woo_st_admin_init')) { $woo_st_url = add_query_arg(array('page' => 'woo_st', 'tab' => null)); $woo_st_target = false; } break; } if ($tab) { if (file_exists(WOO_CE_PATH . 'templates/admin/tabs-' . $tab . '.php')) { include_once WOO_CE_PATH . 'templates/admin/tabs-' . $tab . '.php'; } else { $message = sprintf(__('We couldn\'t load the export template file <code>%s</code> within <code>%s</code>, this file should be present.', 'woo_ce'), 'tabs-' . $tab . '.php', WOO_CE_PATH . 'templates/admin/...'); woo_ce_admin_notice_html($message, 'error'); ob_start(); ?> <p><?php _e('You can see this error for one of a few common reasons', 'woo_ce'); ?> :</p> <ul class="ul-disc"> <li><?php _e('WordPress was unable to create this file when the Plugin was installed or updated', 'woo_ce'); ?> </li> <li><?php _e('The Plugin files have been recently changed and there has been a file conflict', 'woo_ce'); ?> </li> <li><?php _e('The Plugin file has been locked and cannot be opened by WordPress', 'woo_ce'); ?> </li> </ul> <p><?php _e('Jump onto our website and download a fresh copy of this Plugin as it might be enough to fix this issue. If this persists get in touch with us.', 'woo_ce'); ?> </p> <?php ob_end_flush(); } } }
function woo_ce_export_dataset( $export_type = null, &$output = null ) { global $export; $separator = $export->delimiter; $line_ending = woo_ce_get_line_ending(); $export->columns = array(); $export->total_rows = 0; $export->total_columns = 0; $troubleshooting_url = 'http://www.visser.com.au/documentation/store-exporter-deluxe/usage/'; set_transient( WOO_CD_PREFIX . '_running', time(), woo_ce_get_option( 'timeout', MINUTE_IN_SECONDS ) ); // Load up the fatal error notice if we 500 Internal Server Error (memory), hit a server timeout or encounter a fatal PHP error add_action( 'shutdown', 'woo_ce_fatal_error' ); // Drop in our content filters here add_filter( 'sanitize_key', 'woo_ce_sanitize_key' ); switch( $export_type ) { // Products case 'product': $fields = woo_ce_get_product_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_product_field( $key ); } if( $export->gallery_unique ) { $export->fields = woo_ce_unique_product_gallery_fields( $export->fields ); $export->columns = woo_ce_unique_product_gallery_columns( $export->columns, $export->fields ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $products = woo_ce_get_products( $export->args ) ) { $export->total_rows = count( $products ); // XML export if( $export->export_format == 'xml' ) { if( !empty( $export->fields ) ) { foreach( $products as $product ) { $child = $output->addChild( apply_filters( 'woo_ce_export_xml_product_node', sanitize_key( $export_type ) ) ); $product = woo_ce_get_product_data( $product, $export->args, array_keys( $export->fields ) ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $product->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $product->$field, $export_type, $field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( woo_ce_sanitize_xml_string( $product->$field ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $product->$field ) ) ); } } } } } } else if( $export->export_format == 'rss' ) { // RSS export if( !empty( $export->fields ) ) { foreach( $products as $product ) { $child = $output->addChild( 'item' ); $product = woo_ce_get_product_data( $product, $export->args, array_keys( $export->fields ) ); foreach( array_keys( $export->fields ) as $field ) { if( isset( $product->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $product->$field ) ) $child->addChild( sanitize_key( $field ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $product->$field ) ) ); else $child->addChild( sanitize_key( $field ), esc_html( woo_ce_sanitize_xml_string( $product->$field ) ) ); } } } } } } else { // PHPExcel export foreach( $products as $key => $product ) { $products[$key] = woo_ce_get_product_data( $product, $export->args, array_keys( $export->fields ) ); } $output = $products; } unset( $products, $product ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Categories case 'category': $fields = woo_ce_get_category_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_category_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); $category_args = array( 'orderby' => ( isset( $export->args['category_orderby'] ) ? $export->args['category_orderby'] : 'ID' ), 'order' => ( isset( $export->args['category_order'] ) ? $export->args['category_order'] : 'ASC' ), ); if( $categories = woo_ce_get_product_categories( $category_args ) ) { $export->total_rows = count( $categories ); // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { if( !empty( $export->fields ) ) { foreach( $categories as $category ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_category_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $category->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $category->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $category->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $category->$field ) ) ); } } } } } } else { // PHPExcel export $output = $categories; } unset( $categories, $category ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Tags case 'tag': $fields = woo_ce_get_tag_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_tag_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); $tag_args = array( 'orderby' => ( isset( $export->args['tag_orderby'] ) ? $export->args['tag_orderby'] : 'ID' ), 'order' => ( isset( $export->args['tag_order'] ) ? $export->args['tag_order'] : 'ASC' ), ); if( $tags = woo_ce_get_product_tags( $tag_args ) ) { $export->total_rows = count( $tags ); // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { if( !empty( $export->fields ) ) { foreach( $tags as $tag ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_tag_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $tag->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $tag->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $tag->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $tag->$field ) ) ); } } } } } } else { // PHPExcel export $output = $tags; } unset( $tags, $tag ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Brands case 'brand': $fields = woo_ce_get_brand_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_brand_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); $brand_args = array( 'orderby' => ( isset( $export->args['brand_orderby'] ) ? $export->args['brand_orderby'] : 'ID' ), 'order' => ( isset( $export->args['brand_order'] ) ? $export->args['brand_order'] : 'ASC' ), ); if( $brands = woo_ce_get_product_brands( $brand_args ) ) { $export->total_rows = count( $brands ); // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { if( !empty( $export->fields ) ) { foreach( $brands as $brand ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_brand_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $brand->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $brand->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $brand->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $brand->$field ) ) ); } } } } } } else { // PHPExcel export $output = $brands; } unset( $brands, $brand ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Orders case 'order': $fields = woo_ce_get_order_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { // Do not apply Field Editor changes to the unique Order Items Formatting rule if( $export->args['order_items'] == 'unique' ) remove_filter( 'woo_ce_order_fields', 'woo_ce_override_order_field_labels', 11 ); foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_order_field( $key ); // Do not apply Field Editor changes to the unique Order Items Formatting rule if( $export->args['order_items'] == 'unique' ) add_filter( 'woo_ce_order_fields', 'woo_ce_override_order_field_labels', 11 ); } if( $export->args['order_items'] == 'unique' ) { $export->fields = woo_ce_unique_order_item_fields( $export->fields ); $export->columns = woo_ce_unique_order_item_columns( $export->columns, $export->fields ); } $export->data_memory_start = woo_ce_current_memory_usage(); if( $orders = woo_ce_get_orders( 'order', $export->args ) ) { $export->total_columns = $size = count( $export->columns ); // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { if( !empty( $export->fields ) ) { foreach( $orders as $order ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_order_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); $child->addAttribute( 'id', $order ); $order = woo_ce_get_order_data( $order, 'order', $export->args, array_keys( $export->fields ) ); if( in_array( $export->args['order_items'], array( 'combined', 'unique' ) ) ) { // Order items formatting: SPECK-IPHONE|INCASE-NANO|- foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $order->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $order->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $order->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $order->$field ) ) ); } } } } else if( $export->args['order_items'] == 'individual' ) { // Order items formatting: SPECK-IPHONE<br />INCASE-NANO<br />- if( !empty( $order->order_items ) ) { $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 = ''; foreach( $order->order_items as $order_item ) { // 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 = $order_item->product_id; $order->order_items_variation_id = $order_item->variation_id; if( empty( $order_item->sku ) ) $order_item->sku = ''; $order->order_items_sku = $order_item->sku; $order->order_items_name = $order_item->name; $order->order_items_variation = $order_item->variation; $order->order_items_description = woo_ce_format_description_excerpt( $order_item->description ); $order->order_items_excerpt = woo_ce_format_description_excerpt( $order_item->excerpt ); $order->order_items_tax_class = $order_item->tax_class; $order->total_quantity += $order_item->quantity; $order->order_items_quantity = $order_item->quantity; $order->order_items_total = $order_item->total; $order->order_items_subtotal = $order_item->subtotal; $order->order_items_rrp = $order_item->rrp; $order->order_items_stock = $order_item->stock; $order->order_items_tax = $order_item->tax; $order->order_items_tax_subtotal = $order_item->tax_subtotal; $order->order_items_type = $order_item->type; $order->order_items_category = $order_item->category; $order->order_items_tag = $order_item->tag; $order->order_items_total_sales = $order_item->total_sales; $order->order_items_weight = $order_item->weight; $order->order_items_total_weight = $order_item->total_weight; $order = apply_filters( 'woo_ce_order_items_individual', $order, $order_item ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $order->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $order->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $order->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $order->$field ) ) ); } } } } unset( $order->order_items ); } } } } } else { // PHPExcel export if( $export->args['order_items'] == 'individual' ) $output = array(); foreach( $orders as $order ) { if( in_array( $export->args['order_items'], array( 'combined', 'unique' ) ) ) { // Order items formatting: SPECK-IPHONE|INCASE-NANO|- $output[] = woo_ce_get_order_data( $order, 'order', $export->args, array_keys( $export->fields ) ); } else if( $export->args['order_items'] == 'individual' ) { // Order items formatting: SPECK-IPHONE<br />INCASE-NANO<br />- $order = woo_ce_get_order_data( $order, 'order', $export->args, array_keys( $export->fields ) ); if( !empty( $order->order_items ) ) { foreach( $order->order_items as $order_item ) { // 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 = $order_item->product_id; $order->order_items_variation_id = $order_item->variation_id; if( empty( $order_item->sku ) ) $order_item->sku = ''; $order->order_items_sku = $order_item->sku; $order->order_items_name = $order_item->name; $order->order_items_variation = $order_item->variation; $order->order_items_description = $order_item->description; $order->order_items_excerpt = $order_item->excerpt; $order->order_items_tax_class = $order_item->tax_class; $order->total_quantity += $order_item->quantity; $order->order_items_quantity = $order_item->quantity; $order->order_items_total = $order_item->total; $order->order_items_subtotal = $order_item->subtotal; $order->order_items_rrp = $order_item->rrp; $order->order_items_stock = $order_item->stock; $order->order_items_tax = $order_item->tax; $order->order_items_tax_subtotal = $order_item->tax_subtotal; $order->order_items_type = $order_item->type; $order->order_items_category = $order_item->category; $order->order_items_tag = $order_item->tag; $order->order_items_total_sales = $order_item->total_sales; $order->order_items_weight = $order_item->weight; $order->order_items_total_weight = $order_item->total_weight; $order = apply_filters( 'woo_ce_order_items_individual', $order, $order_item ); // This fixes the Order Items for this Order Items Formatting rule $output[] = (object)(array)$order; } } } } } unset( $orders, $order ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Customers case 'customer': $fields = woo_ce_get_customer_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_customer_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $customers = woo_ce_get_orders( 'customer', $export->args ) ) { $export->total_rows = count( $customers ); // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { if( !empty( $export->fields ) ) { foreach( $customers as $customer ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_customer_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $customer->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $customer->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $customer->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $customer->$field ) ) ); } } } } } } else { // PHPExcel export $output = $customers; } unset( $customers, $customer ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Users case 'user': $fields = woo_ce_get_user_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_user_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $users = woo_ce_get_users( $export->args ) ) { // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { $export->total_rows = count( $users ); if( !empty( $export->fields ) ) { foreach( $users as $user ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_user_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); $user = woo_ce_get_user_data( $user, $export->args, array_keys( $export->fields ) ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $user->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $user->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $user->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $user->$field ) ) ); } } } } } } else { // PHPExcel export foreach( $users as $key => $user ) $users[$key] = woo_ce_get_user_data( $user, $export->args, array_keys( $export->fields ) ); $output = $users; } unset( $users, $user ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Coupons case 'coupon': $fields = woo_ce_get_coupon_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_coupon_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $coupons = woo_ce_get_coupons( $export->args ) ) { // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { $export->total_rows = count( $coupons ); if( !empty( $export->fields ) ) { foreach( $coupons as $coupon ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_coupon_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); $coupon = woo_ce_get_coupon_data( $coupon, $export->args, array_keys( $export->fields ) ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $coupon->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $coupon->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $coupon->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $coupon->$field ) ) ); } } } } } } else { // PHPExcel export foreach( $coupons as $key => $coupon ) { $coupons[$key] = woo_ce_get_coupon_data( $coupon, $export->args, array_keys( $export->fields ) ); } $output = $coupons; } unset( $coupons, $coupon ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Subscriptions case 'subscription': $fields = woo_ce_get_subscription_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_subscription_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $subscriptions = woo_ce_get_subscriptions( $export->args ) ) { $export->total_rows = count( $subscriptions ); // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { if( !empty( $export->fields ) ) { foreach( $subscriptions as $subscription ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_subscription_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $subscription->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $subscription->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $subscription->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $subscription->$field ) ) ); } } } } } } else { // PHPExcel export $output = $subscriptions; } unset( $subscriptions, $subscription ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Product Vendors case 'product_vendor': $fields = woo_ce_get_product_vendor_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_product_vendor_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $product_vendors = woo_ce_get_product_vendors( $export->args ) ) { // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { $export->total_rows = count( $product_vendors ); if( !empty( $export->fields ) ) { foreach( $product_vendors as $product_vendor ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_product_vendor_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); $product_vendor = woo_ce_get_product_vendor_data( $product_vendor, $export->args, array_keys( $export->fields ) ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $product_vendor->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $product_vendor->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $product_vendor->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $product_vendor->$field ) ) ); } } } } } } else { // PHPExcel export foreach( $product_vendors as $key => $product_vendor ) { $product_vendors[$key] = woo_ce_get_product_vendor_data( $product_vendor, $export->args, array_keys( $export->fields ) ); } $output = $product_vendors; } unset( $product_vendors, $product_vendor ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Commissions case 'commission': $fields = woo_ce_get_commission_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_commission_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $commissions = woo_ce_get_commissions( $export->args ) ) { // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { $export->total_rows = count( $commissions ); if( !empty( $export->fields ) ) { foreach( $commissions as $commission ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_commission_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); $commission = woo_ce_get_commission_data( $commission, $export->args, array_keys( $export->fields ) ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $commission->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $commission->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $commission->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $commission->$field ) ) ); } } } } } } else { // PHPExcel export foreach( $commissions as $key => $commission ) { $commissions[$key] = woo_ce_get_commission_data( $commission, $export->args, array_keys( $export->fields ) ); } $output = $commissions; } unset( $commissions, $commission ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; // Shipping Classes case 'shipping_class': $fields = woo_ce_get_shipping_class_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_shipping_class_field( $key ); } $export->total_columns = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $shipping_classes = woo_ce_get_shipping_classes( $export->args ) ) { // XML, RSS export if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { $export->total_rows = count( $shipping_classes ); if( !empty( $export->fields ) ) { foreach( $shipping_classes as $shipping_class ) { if( $export->export_format == 'xml' ) $child = $output->addChild( apply_filters( 'woo_ce_export_xml_shipping_class_node', sanitize_key( $export_type ) ) ); else if( $export->export_format == 'rss' ) $child = $output->addChild( 'item' ); foreach( array_keys( $export->fields ) as $key => $field ) { if( isset( $shipping_class->$field ) ) { if( !is_array( $field ) ) { if( woo_ce_is_xml_cdata( $shipping_class->$field ) ) $child->addChild( sanitize_key( $export->columns[$key] ) )->addCData( esc_html( woo_ce_sanitize_xml_string( $shipping_class->$field ) ) ); else $child->addChild( sanitize_key( $export->columns[$key] ), esc_html( woo_ce_sanitize_xml_string( $shipping_class->$field ) ) ); } } } } } } else { // PHPExcel export $output = $shipping_classes; } unset( $shipping_classes, $shipping_class ); } $export->data_memory_end = woo_ce_current_memory_usage(); break; /* // Attributes case 'attribute': $fields = woo_ce_get_attribute_fields( 'summary' ); if( $export->fields = array_intersect_assoc( (array)$export->fields, $fields ) ) { foreach( $export->fields as $key => $field ) $export->columns[] = woo_ce_get_attribute_field( $key ); } $export->total_columns = $size = count( $export->columns ); $export->data_memory_start = woo_ce_current_memory_usage(); if( $attributes = woo_ce_get_attributes( $export->args ) ) { $export->total_rows = count( $attributes ); // Generate the export headers if( $export->header_formatting && in_array( $export->export_format, array( 'csv', 'xls' ) ) ) { for( $i = 0; $i < $size; $i++ ) { if( $i == ( $size - 1 ) ) $output .= woo_ce_escape_csv_value( $export->columns[$i], $export->delimiter, $export->escape_formatting ) . $line_ending; else $output .= woo_ce_escape_csv_value( $export->columns[$i], $export->delimiter, $export->escape_formatting ) . $separator; } } if( !empty( $export->fields ) ) { foreach( $atributes as $attribute ) { if( $export->export_format == 'xml' ) $child = $output->addChild( $export->type, 0, -1 ); } } } $export->data_memory_end = woo_ce_current_memory_usage(); unset( $export->fields ); break; */ } // Remove our content filters here to play nice with other Plugins remove_filter( 'sanitize_key', 'woo_ce_sanitize_key' ); // Remove our fatal error notice so not to conflict with the CRON or scheduled export engine remove_action( 'shutdown', 'woo_ce_fatal_error' ); // Export completed successfully delete_transient( WOO_CD_PREFIX . '_running' ); // Check if we're using PHPExcel or generic export engine if( WOO_CD_DEBUG || in_array( $export->export_format, array( 'xml', 'rss' ) ) ) { // Check that the export file is populated, export columns have been assigned and rows counted if( !empty( $output ) && $export->total_rows && $export->total_columns ) { if( WOO_CD_DEBUG && !in_array( $export->export_format, array( 'csv', 'xls', 'xlsx' ) ) && ( !$export->cron && !$export->scheduled_export ) ) { if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) $output = woo_ce_format_xml( $output ); $response = set_transient( WOO_CD_PREFIX . '_debug_log', base64_encode( $output ), woo_ce_get_option( 'timeout', MINUTE_IN_SECONDS ) ); if( $response !== true ) { $message = __( 'The export contents were too large to store in a single WordPress transient, use the Volume offset / Limit volume options to reduce the size of your export and try again.', 'woo_ce' ) . ' (<a href="' . $troubleshooting_url . '" target="_blank">' . __( 'Need help?', 'woo_ce' ) . '</a>)'; if( function_exists( 'woo_cd_admin_notice' ) ) woo_cd_admin_notice( $message, 'error' ); else error_log( sprintf( '[store-exporter-deluxe] woo_ce_export_dataset() - %s', $message ) ); return; } else { return true; } } else { return $output; } } } else { return $output; } }
function woo_ce_get_subscription_field( $name = null, $format = 'name' ) { $output = ''; if( $name ) { $fields = woo_ce_get_subscription_fields(); $size = count( $fields ); for( $i = 0; $i < $size; $i++ ) { if( $fields[$i]['name'] == $name ) { switch( $format ) { case 'name': $output = $fields[$i]['label']; break; case 'full': $output = $fields[$i]; break; } $i = $size; } } } return $output; }