コード例 #1
0
	function woo_ce_export_type_label( $export_type = '', $echo = false ) {

		$output = '';
		if( !empty( $export_type ) ) {
			$export_types = woo_ce_return_export_types();
			if( array_key_exists( $export_type, $export_types ) )
				$output = $export_types[$export_type];
		}
		if( $echo )
			echo $output;
		else
			return $output;

	}
コード例 #2
0
ファイル: admin.php プロジェクト: mynein/myne
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();
        }
    }
}
コード例 #3
0
	function woo_cd_admin_init() {

		global $export, $wp_roles;

		$troubleshooting_url = 'http://www.visser.com.au/documentation/store-exporter-deluxe/usage/';

		// Time to tell the store owner if we were unable to disable the basic Store Exporter
		if( defined( 'WOO_CE_PREFIX' ) ) {
			// Display notice if we were unable to de-activate basic Store Exporter
			if( ( is_plugin_active( 'woocommerce-exporter/exporter.php' ) || is_plugin_active( 'woocommerce-store-exporter/exporter.php' ) ) && current_user_can( 'activate_plugins' ) ) {
				$plugins_url = esc_url( add_query_arg( '', '', 'plugins.php' ) );
				$message = sprintf( __( 'We did our best to de-activate Store Exporter for you but may have failed, please check that the basic Store Exporter is de-activated from the <a href="%s">Plugins screen</a>.', 'woo_ce' ), $plugins_url );
				woo_cd_admin_notice( $message, 'error', array( 'plugins.php', 'update-core.php' ) );
			}
		}

		// Detect if another e-Commerce platform is activated
		if( !woo_is_woo_activated() && ( woo_is_jigo_activated() || woo_is_wpsc_activated() ) ) {
			$message = sprintf( __( 'We have detected another e-Commerce Plugin than WooCommerce activated, please check that you are using Store Exporter Deluxe for the correct platform. <a href="%s" target="_blank">Need help?</a>', 'woo_ce' ), $troubleshooting_url );
			woo_cd_admin_notice( $message, 'error', 'plugins.php' );
		} else if( !woo_is_woo_activated() ) {
			$message = sprintf( __( 'We have been unable to detect the WooCommerce Plugin activated on this WordPress site, please check that you are using Store Exporter Deluxe for the correct platform. <a href="%s" target="_blank">Need help?</a>', 'woo_ce' ), $troubleshooting_url );
			woo_cd_admin_notice( $message, 'error', 'plugins.php' );
		}

		// Detect if WooCommerce Subscriptions Exporter is activated
		if( function_exists( 'wc_subs_exporter_admin_init' ) ) {
			$message = sprintf( __( 'We have detected a WooCommerce Plugin that is activated and known to conflict with Store Exporter Deluxe, please de-activate WooCommerce Subscriptions Exporter to resolve export issues. <a href="%s" target="_blank">Need help?</a>', 'woo_ce' ), $troubleshooting_url );
			woo_cd_admin_notice( $message, 'error', array( 'plugins.php', 'admin.php' ) );
		}

		// Displays a HTML notice where we have detected the site has moved or this is staging site
		if(
			woo_ce_get_option( 'duplicate_site_prompt', 0 )
			&& ( woo_ce_get_option( 'override_duplicate_site_prompt', 0 ) == false )
			&& ( woo_ce_get_option( 'dismiss_duplicate_site_prompt', 0 ) == false )
		) {
			$dismiss_url = esc_url( add_query_arg( 'action', 'dismiss_duplicate_site_prompt' ) );
			$override_url = esc_url( add_query_arg( 'action', 'override_duplicate_site_prompt' ) );
			$message = __( 'It looks like this site has moved or is a duplicate site. Store Exporter Deluxe has disabled scheduled exports on this site to prevent duplicate scheduled exports being generated from a staging or test environment.', 'woo_ce' ) . '<br /><br /><a href="' . $override_url . '" class="button-primary">' . __( 'Continue running scheduled exports', 'woo_ce' ) . '</a>' . '<span style="float:right;"><a href="' . $dismiss_url . '">' . __( 'Dismiss', 'woo_ce' ) . '</a></span>';
			woo_cd_admin_notice( $message, 'error' );
		}

		add_action( 'after_plugin_row_' . WOO_CD_RELPATH, 'woo_ce_admin_plugin_row' );

		// Check the User has the view_woocommerce_reports capability
		if( current_user_can( 'view_woocommerce_reports' ) ) {
			// Load Dashboard widget for Scheduled Exports
			add_action( 'wp_dashboard_setup', 'woo_ce_dashboard_setup' );
			// Add Export Status to Orders screen
			add_filter( 'manage_edit-shop_order_columns', 'woo_ce_admin_order_column_headers', 20 );
			add_action( 'manage_shop_order_posts_custom_column', 'woo_ce_admin_order_column_content' );
			// Load Download buttons for Orders screen
			wp_enqueue_style( 'dashicons' );
			wp_enqueue_style( 'woo_ce_styles', plugins_url( '/templates/admin/export.css', WOO_CD_RELPATH ) );
			// Add our export to CSV, XML, XLS, XLSX action buttons
			add_filter( 'woocommerce_admin_order_actions', 'woo_ce_admin_order_actions', 10, 2 );
			add_action( 'wp_ajax_woo_ce_export_order', 'woo_ce_ajax_export_order' );
			// Add Download as... options to Orders Bulk
			add_action( 'admin_footer', 'woo_ce_admin_order_bulk_actions' );
			add_action( 'load-edit.php', 'woo_ce_admin_order_process_bulk_action' );
			// Add Download as... options to Edit Order Actions
			add_action( 'woocommerce_order_actions', 'woo_ce_admin_order_single_actions' );
			add_action( 'woocommerce_order_action_woo_ce_export_order_csv', 'woo_ce_admin_order_single_export_csv' );
			add_action( 'woocommerce_order_action_woo_ce_export_order_xml', 'woo_ce_admin_order_single_export_xml' );
			add_action( 'woocommerce_order_action_woo_ce_export_order_xls', 'woo_ce_admin_order_single_export_xls' );
			add_action( 'woocommerce_order_action_woo_ce_export_order_xlsx', 'woo_ce_admin_order_single_export_xlsx' );
		}

		// Check that we are on the Store Exporter screen
		$page = ( isset($_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : false );
		if( $page != strtolower( WOO_CD_PREFIX ) )
			return;

		// Process any pre-export notice confirmations
		$action = woo_get_action();
		switch( $action ) {

			// Delete all Archives
			case 'nuke_archives':
				// We need to verify the nonce.
				if( !empty( $_GET ) && check_admin_referer( 'woo_ce_nuke_archives' ) ) {
					if( woo_ce_nuke_archive_files() ) {
						$message = __( 'All existing Archives and their export files have been deleted from your WordPress site.', 'woo_ce' );
						woo_cd_admin_notice( $message );
					} else {
						$message = __( 'There were no existing Archives to be deleted from your WordPress site.', 'woo_ce' );
						woo_cd_admin_notice( $message, 'error' );
					}
				}
				break;

			// Prompt on Export screen when insufficient memory (less than 64M is allocated)
			case 'dismiss_memory_prompt':
				woo_ce_update_option( 'dismiss_memory_prompt', 1 );
				$url = esc_url( add_query_arg( 'action', null ) );
				wp_redirect( $url );
				exit();
				break;

			// Prompt on Export screen when PHP configuration option max_execution_time cannot be increased
			case 'dismiss_execution_time_prompt':
				woo_ce_update_option( 'dismiss_execution_time_prompt', 1 );
				$url = esc_url( add_query_arg( 'action', null ) );
				wp_redirect( $url );
				exit();
				break;

			// Prompt on Export screen when insufficient memory (less than 64M is allocated)
			case 'dismiss_php_legacy':
				woo_ce_update_option( 'dismiss_php_legacy', 1 );
				$url = esc_url( add_query_arg( 'action', null ) );
				wp_redirect( $url );
				exit();
				break;

			case 'dismiss_subscription_prompt':
				woo_ce_update_option( 'dismiss_subscription_prompt', 1 );
				$url = esc_url( add_query_arg( 'action', null ) );
				wp_redirect( $url );
				exit();
				break;

			case 'dismiss_duplicate_site_prompt':
				woo_ce_update_option( 'dismiss_duplicate_site_prompt', 1 );
				$url = esc_url( add_query_arg( 'action', null ) );
				wp_redirect( $url );
				exit();
				break;

			case 'dismiss_secure_archives_prompt':
				woo_ce_update_option( 'dismiss_secure_archives_prompt', 1 );
				$url = esc_url( add_query_arg( 'action', null ) );
				wp_redirect( $url );
				exit();
				break;

			case 'override_duplicate_site_prompt':
				woo_ce_update_option( 'override_duplicate_site_prompt', 1 );
				// Enable scheduled exports again
				woo_ce_update_option( 'enable_auto', 1 );
				$url = esc_url( add_query_arg( 'action', null ) );
				wp_redirect( $url );
				exit();
				break;

			// Move legacy archives exports to the sed-exports directory within Uploads
			case 'relocate_archived_exports':

				// Create the sed-exports directory if it hasn't been
				woo_cd_create_secure_archives_dir();

				$updated = 0;
				if( $files = woo_ce_get_archive_files() ) {
					foreach( $files as $key => $file ) {
						$filepath = get_attached_file( $file->ID );
						// Check for archived exports that have not been moved to sed-exports
						if( strpos( $filepath, 'sed-exports' ) == false ) {
							// Move the export

							// Update the Post meta key _wp_attached_file
							$attached_file = get_post_meta( $file->ID, '_wp_attached_file', true );
							if( !empty( $attached_file ) )
								$attached_file = trailingslashit( 'sed-exports' ) . basename( $attached_file );
							$updated++;
						}
					}
				}

				// Show the response
				$message = sprintf( __( 'That\'s sorted, we\'ve relocated %d export files to the newly created <code>sed-exports</code> folder within the WordPress Uploads directory. Happy exporting!', 'woo_ce' ), $updated );
				woo_cd_admin_notice_html( $message );
				break;

			// Save skip overview preference
			case 'skip_overview':
				$skip_overview = false;
				if( isset( $_POST['skip_overview'] ) )
					$skip_overview = 1;
				woo_ce_update_option( 'skip_overview', $skip_overview );

				if( $skip_overview == 1 ) {
					$url = esc_url( add_query_arg( 'tab', 'export' ) );
					wp_redirect( $url );
					exit();
				}
				break;

			// This is where the magic happens
			case 'export':

				// Make sure we play nice with other WooCommerce and WordPress exporters
				if( !isset( $_POST['woo_ce_export'] ) )
					return;

				check_admin_referer( 'manual_export', 'woo_ce_export' );

				// Set up the basic export options
				$export = new stdClass();
				$export->cron = 0;
				$export->scheduled_export = 0;
				$export->start_time = time();
				$export->idle_memory_start = woo_ce_current_memory_usage();
				$export->delete_file = woo_ce_get_option( 'delete_file', 1 );
				$export->encoding = woo_ce_get_option( 'encoding', get_option( 'blog_charset', 'UTF-8' ) );
				// Reset the Encoding if corrupted
				if( $export->encoding == '' || $export->encoding == false || $export->encoding == 'System default' ) {
					error_log( '[store-exporter-deluxe] Warning: Encoding export option was corrupted, defaulted to UTF-8' );
					$export->encoding = 'UTF-8';
					woo_ce_update_option( 'encoding', 'UTF-8' );
				}
				$export->delimiter = woo_ce_get_option( 'delimiter', ',' );
				// Reset the Delimiter if corrupted
				if( $export->delimiter == '' || $export->delimiter == false ) {
					error_log( '[store-exporter-deluxe] Warning: Delimiter export option was corrupted, defaulted to ,' );
					$export->delimiter = ',';
					woo_ce_update_option( 'delimiter', ',' );
				} else if( $export->delimiter == 'TAB' ) {
					$export->delimiter = "\t";
				}
				$export->category_separator = woo_ce_get_option( 'category_separator', '|' );
				// Reset the Category Separator if corrupted
				if( $export->category_separator == '' || $export->category_separator == false ) {
					error_log( '[store-exporter-deluxe] Warning: Category Separator export option was corrupted, defaulted to |' );
					$export->category_separator = '|';
					woo_ce_update_option( 'category_separator', '|' );
				}
				// Override for line break (LF) support in Category Separator
				if( $export->category_separator == 'LF' )
					$export->category_separator = "\n";
				$export->bom = woo_ce_get_option( 'bom', 1 );
				$export->escape_formatting = woo_ce_get_option( 'escape_formatting', 'all' );
				// Reset the Escape Formatting if corrupted
				if( $export->escape_formatting == '' || $export->escape_formatting == false ) {
					error_log( '[store-exporter-deluxe] Warning: Escape Formatting export option was corrupted, defaulted to all' );
					$export->escape_formatting = 'all';
					woo_ce_update_option( 'escape_formatting', 'all' );
				}
				$export->header_formatting = woo_ce_get_option( 'header_formatting', 1 );
				$export->date_format = woo_ce_get_option( 'date_format', 'd/m/Y' );
				// Reset the Date Format if corrupted
				if( $export->date_format == '1' || $export->date_format == '' || $export->date_format == false ) {
					error_log( '[store-exporter-deluxe] Warning: Date Format export option was corrupted, defaulted to d/m/Y' );
					$export->date_format = 'd/m/Y';
					woo_ce_update_option( 'date_format', 'd/m/Y' );
				}

				// Save export option changes made on the Export screen
				$export->limit_volume = ( isset( $_POST['limit_volume'] ) ? sanitize_text_field( $_POST['limit_volume'] ) : '' );
				woo_ce_update_option( 'limit_volume', $export->limit_volume );
				if( $export->limit_volume == '' )
					$export->limit_volume = -1;
				$export->offset = ( isset( $_POST['offset'] ) ? sanitize_text_field( $_POST['offset'] ) : '' );
				woo_ce_update_option( 'offset', $export->offset );
				if( $export->offset == '' )
					$export->offset = 0;
				$export->type = ( isset( $_POST['dataset'] ) ? sanitize_text_field( $_POST['dataset'] ) : false );
				if( in_array( $export->type, array( 'product', 'category', 'tag', 'brand', 'order' ) ) ) {
					$export->description_excerpt_formatting = ( isset( $_POST['description_excerpt_formatting'] ) ? absint( $_POST['description_excerpt_formatting'] ) : false );
					if( $export->description_excerpt_formatting <> woo_ce_get_option( 'description_excerpt_formatting' ) )
						woo_ce_update_option( 'variation_formatting', $export->description_excerpt_formatting );
				}
				woo_ce_update_option( 'export_format', sanitize_text_field( $_POST['export_format'] ) );

				// Set default values for all export options to be later passed onto the export process
				$export->fields = array();
				$export->fields_order = false;
				$export->export_format = woo_ce_get_option( 'export_format', 'csv' );

				// Product sorting
				$export->product_categories = false;
				$export->product_tags = false;
				$export->product_brands = false;
				$export->product_vendors = false;
				$export->product_status = false;
				$export->product_type = false;
				$export->product_stock = false;
				$export->product_language = false;
				$export->product_orderby = false;
				$export->product_order = false;
				$export->gallery_formatting = false;
				$export->gallery_unique = false;
				$export->max_product_gallery = false;
				$export->upsell_formatting = false;
				$export->crosssell_formatting = false;
				$export->variation_formatting = false;

				// Category sorting
				$export->category_language = false;
				$export->category_orderby = false;
				$export->category_order = false;

				// Tag sorting
				$export->tag_language = false;
				$export->tag_orderby = false;
				$export->tag_order = false;

				// Brand sorting
				$export->brand_orderby = false;
				$export->brand_order = false;

				// Order sorting
				$export->order_dates_filter = false;
				$export->order_dates_from = '';
				$export->order_dates_to = '';
				$export->order_dates_filter_variable = false;
				$export->order_dates_filter_variable_length = false;
				$export->order_status = false;
				$export->order_customer = false;
				$export->order_billing_country = false;
				$export->order_shipping_country = false;
				$export->order_user_roles = false;
				$export->order_product = false;
				$export->order_coupons = false;
				$export->order_category = false;
				$export->order_tag = false;
				$export->order_brand = false;
				$export->order_ids = false;
				$export->order_payment = false;
				$export->order_shipping = false;
				$export->order_items = 'combined';
				$export->order_items_types = false;
				$export->order_orderby = false;
				$export->order_order = false;
				$export->max_order_items = false;

				// User sorting
				$export->user_orderby = false;
				$export->user_order = false;

				// Coupon sorting
				$export->coupon_discount_types = false;
				$export->coupon_orderby = false;
				$export->coupon_order = false;

				// Subscription sorting
				$export->subscription_status = false;
				$export->subscription_product = false;

				// Commission sorting
				$export->commission_dates_filter = false;
				$export->commission_dates_from = '';
				$export->commission_dates_to = '';
				$export->commission_dates_filter_variable = false;
				$export->commission_dates_filter_variable_length = false;
				$export->commission_product_vendors = false;
				$export->commission_status = false;
				$export->commission_orderby = false;
				$export->commission_order = false;

				// Shipping Class sorting
				$export->shipping_class_orderby = false;
				$export->shipping_class_order = false;

				if( !empty( $export->type ) ) {
					$export->fields = ( isset( $_POST[$export->type . '_fields'] ) ? array_map( 'sanitize_text_field', $_POST[$export->type . '_fields'] ) : false );
					$export->fields_order = ( isset( $_POST[$export->type . '_fields_order'] ) ? array_map( 'absint', $_POST[$export->type . '_fields_order'] ) : false );
					woo_ce_update_option( 'last_export', $export->type );
				}
				switch( $export->type ) {

					case 'product':
						// Set up dataset specific options
						$export->product_categories = ( isset( $_POST['product_filter_category'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['product_filter_category'] ) ) : false );
						$export->product_tags = ( isset( $_POST['product_filter_tag'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['product_filter_tag'] ) ) : false );
						$export->product_brands = ( isset( $_POST['product_filter_brand'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['product_filter_brand'] ) ) : false );
						$export->product_vendors = ( isset( $_POST['product_filter_vendor'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['product_filter_vendor'] ) ) : false );
						$export->product_status = ( isset( $_POST['product_filter_status'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['product_filter_status'] ) ) : false );
						$export->product_type = ( isset( $_POST['product_filter_type'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['product_filter_type'] ) ) : false );
						$export->product_stock = ( isset( $_POST['product_filter_stock'] ) ? sanitize_text_field( $_POST['product_filter_stock'] ) : false );
						$export->product_language = ( isset( $_POST['product_filter_language'] ) ? array_map( 'sanitize_text_field', $_POST['product_filter_language'] ) : false );
						$export->product_orderby = ( isset( $_POST['product_orderby'] ) ? sanitize_text_field( $_POST['product_orderby'] ) : false );
						$export->product_order = ( isset( $_POST['product_order'] ) ? sanitize_text_field( $_POST['product_order'] ) : false );
						$export->gallery_formatting = ( isset( $_POST['product_gallery_formatting'] ) ? absint( $_POST['product_gallery_formatting'] ) : false );
						$export->gallery_unique = ( isset( $_POST['product_gallery_unique'] ) ? absint( $_POST['product_gallery_unique'] ) : false );
						$export->upsell_formatting = ( isset( $_POST['product_upsell_formatting'] ) ? absint( $_POST['product_upsell_formatting'] ) : false );
						$export->crosssell_formatting = ( isset( $_POST['product_crosssell_formatting'] ) ? absint( $_POST['product_crosssell_formatting'] ) : false );
						$export->variation_formatting = ( isset( $_POST['variation_formatting'] ) ? absint( $_POST['variation_formatting'] ) : false );

						// Save dataset export specific options
						if( $export->product_orderby <> woo_ce_get_option( 'product_orderby' ) )
							woo_ce_update_option( 'product_orderby', $export->product_orderby );
						if( $export->product_order <> woo_ce_get_option( 'product_order' ) )
							woo_ce_update_option( 'product_order', $export->product_order );
						if( $export->upsell_formatting <> woo_ce_get_option( 'upsell_formatting' ) )
							woo_ce_update_option( 'upsell_formatting', $export->upsell_formatting );
						if( $export->crosssell_formatting <> woo_ce_get_option( 'crosssell_formatting' ) )
							woo_ce_update_option( 'crosssell_formatting', $export->crosssell_formatting );
						if( $export->variation_formatting <> woo_ce_get_option( 'variation_formatting' ) )
							woo_ce_update_option( 'variation_formatting', $export->variation_formatting );
						if( $export->gallery_formatting <> woo_ce_get_option( 'gallery_formatting' ) )
							woo_ce_update_option( 'gallery_formatting', $export->gallery_formatting );
						if( $export->gallery_unique <> woo_ce_get_option( 'gallery_unique' ) )
							woo_ce_update_option( 'gallery_unique', $export->gallery_unique );
						if( isset( $_POST['max_product_gallery'] ) ) {
							$export->max_product_gallery = absint( $_POST['max_product_gallery'] );
							if( $export->max_product_gallery <> woo_ce_get_option( 'max_product_gallery' ) )
								woo_ce_update_option( 'max_product_gallery', $export->max_product_gallery );
						}
						break;

					case 'category':
						// Set up dataset specific options
						$export->category_language = ( isset( $_POST['category_filter_language'] ) ? array_map( 'sanitize_text_field', $_POST['category_filter_language'] ) : false );
						$export->category_orderby = ( isset( $_POST['category_orderby'] ) ? sanitize_text_field( $_POST['category_orderby'] ) : false );
						$export->category_order = ( isset( $_POST['category_order'] ) ? sanitize_text_field( $_POST['category_order'] ) : false );

						// Save dataset export specific options
						if( $export->category_orderby <> woo_ce_get_option( 'category_orderby' ) )
							woo_ce_update_option( 'category_orderby', $export->category_orderby );
						if( $export->category_order <> woo_ce_get_option( 'category_order' ) )
							woo_ce_update_option( 'category_order', $export->category_order );
						break;

					case 'tag':
						// Set up dataset specific options
						$export->tag_language = ( isset( $_POST['tag_filter_language'] ) ? array_map( 'sanitize_text_field', $_POST['tag_filter_language'] ) : false );
						$export->tag_orderby = ( isset( $_POST['tag_orderby'] ) ? sanitize_text_field( $_POST['tag_orderby'] ) : false );
						$export->tag_order = ( isset( $_POST['tag_order'] ) ? sanitize_text_field( $_POST['tag_order'] ) : false );

						// Save dataset export specific options
						if( $export->tag_orderby <> woo_ce_get_option( 'tag_orderby' ) )
							woo_ce_update_option( 'tag_orderby', $export->tag_orderby );
						if( $export->tag_order <> woo_ce_get_option( 'tag_order' ) )
							woo_ce_update_option( 'tag_order', $export->tag_order );
						break;

					case 'brand':
						// Set up dataset specific options
						$export->brand_orderby = ( isset( $_POST['brand_orderby'] ) ? sanitize_text_field( $_POST['brand_orderby'] ) : false );
						$export->brand_order = ( isset( $_POST['brand_order'] ) ? sanitize_text_field( $_POST['brand_order'] ) : false );

						// Save dataset export specific options
						if( $export->brand_orderby <> woo_ce_get_option( 'brand_orderby' ) )
							woo_ce_update_option( 'brand_orderby', $export->brand_orderby );
						if( $export->brand_order <> woo_ce_get_option( 'brand_order' ) )
							woo_ce_update_option( 'brand_order', $export->brand_order );
						break;

					case 'order':
						// Set up dataset specific options
						$export->order_dates_filter = ( isset( $_POST['order_dates_filter'] ) ? sanitize_text_field( $_POST['order_dates_filter'] ) : false );
						$export->order_dates_from = sanitize_text_field( $_POST['order_dates_from'] );
						$export->order_dates_to = sanitize_text_field( $_POST['order_dates_to'] );
						$export->order_dates_filter_variable = ( isset( $_POST['order_dates_filter_variable'] ) ? absint( $_POST['order_dates_filter_variable'] ) : false );
						$export->order_dates_filter_variable_length = ( isset( $_POST['order_dates_filter_variable_length'] ) ? sanitize_text_field( $_POST['order_dates_filter_variable_length'] ) : false );
						$export->order_status = ( isset( $_POST['order_filter_status'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['order_filter_status'] ) ) : false );
						$export->order_customer = ( isset( $_POST['order_filter_customer'] ) ? array_map( 'absint', $_POST['order_filter_customer'] ) : false );
						$export->order_billing_country = ( isset( $_POST['order_filter_billing_country'] ) ? array_map( 'sanitize_text_field', $_POST['order_filter_billing_country'] ) : false );
						$export->order_shipping_country = ( isset( $_POST['order_filter_shipping_country'] ) ? array_map( 'sanitize_text_field', $_POST['order_filter_shipping_country'] ) : false );
						$export->order_user_roles = ( isset( $_POST['order_filter_user_role'] ) ? woo_ce_format_user_role_filters( array_map( 'sanitize_text_field', $_POST['order_filter_user_role'] ) ) : false );
						$export->order_coupons = ( isset( $_POST['order_filter_coupon'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['order_filter_coupon'] ) ) : false );
						$export->order_product = ( isset( $_POST['order_filter_product'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['order_filter_product'] ) ) : false );
						$export->order_category = ( isset( $_POST['order_filter_category'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['order_filter_category'] ) ) : false );
						$export->order_tag = ( isset( $_POST['order_filter_tag'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['order_filter_tag'] ) ) : false );
						$export->order_brand = ( isset( $_POST['order_filter_brand'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['order_filter_brand'] ) ) : false );
						$export->order_ids = ( isset( $_POST['order_filter_id'] ) ? sanitize_text_field( $_POST['order_filter_id'] ) : false );
						$export->order_payment = ( isset( $_POST['order_filter_payment_gateway'] ) ? array_map( 'sanitize_text_field', $_POST['order_filter_payment_gateway'] ) : false );
						$export->order_shipping = ( isset( $_POST['order_filter_shipping_method'] ) ? array_map( 'sanitize_text_field', $_POST['order_filter_shipping_method'] ) : false );
						$export->order_orderby = ( isset( $_POST['order_orderby'] ) ? sanitize_text_field( $_POST['order_orderby'] ) : false );
						$export->order_order = ( isset( $_POST['order_order'] ) ? sanitize_text_field( $_POST['order_order'] ) : false );

						// Save dataset export specific options
						if( isset( $_POST['order_items'] ) ) {
							$export->order_items = sanitize_text_field( $_POST['order_items'] );
							if( $export->order_items <> woo_ce_get_option( 'order_items_formatting' ) )
								woo_ce_update_option( 'order_items_formatting', $export->order_items );
						}
						if( isset( $_POST['order_items_types'] ) ) {
							$export->order_items_types = array_map( 'sanitize_text_field', $_POST['order_items_types'] );
							if( $export->order_items_types <> woo_ce_get_option( 'order_items_types' ) )
								woo_ce_update_option( 'order_items_types', $export->order_items_types );
						}
						if( isset( $_POST['max_order_items'] ) ) {
							$export->max_order_items = absint( $_POST['max_order_items'] );
							if( $export->max_order_items <> woo_ce_get_option( 'max_order_items' ) )
								woo_ce_update_option( 'max_order_items', $export->max_order_items );
						}
						if( $export->order_orderby <> woo_ce_get_option( 'order_orderby' ) )
							woo_ce_update_option( 'order_orderby', $export->order_orderby );
						if( $export->order_order <> woo_ce_get_option( 'order_order' ) )
							woo_ce_update_option( 'order_order', $export->order_order );
						break;

					case 'customer':
						// Set up dataset specific options

						// Save dataset export specific options
						$export->order_status = ( isset( $_POST['customer_filter_status'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['customer_filter_status'] ) ) : false );
						$export->order_user_roles = ( isset( $_POST['customer_filter_user_role'] ) ? woo_ce_format_user_role_filters( array_map( 'sanitize_text_field', $_POST['customer_filter_user_role'] ) ) : false );
						break;

					case 'user':
						// Set up dataset specific options
						$export->user_orderby = ( isset( $_POST['user_orderby'] ) ? sanitize_text_field( $_POST['user_orderby'] ) : false );
						$export->user_order = ( isset( $_POST['user_order'] ) ? sanitize_text_field( $_POST['user_order'] ) : false );

						// Save dataset export specific options
						if( $export->user_orderby <> woo_ce_get_option( 'user_orderby' ) )
							woo_ce_update_option( 'user_orderby', $export->user_orderby );
						if( $export->user_order <> woo_ce_get_option( 'user_order' ) )
							woo_ce_update_option( 'user_order', $export->user_order );
						break;

					case 'coupon':
						// Set up dataset specific options
						$export->coupon_discount_types = ( isset( $_POST['coupon_filter_discount_type'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['coupon_filter_discount_type'] ) ) : false );
						$export->coupon_orderby = ( isset( $_POST['coupon_orderby'] ) ? sanitize_text_field( $_POST['coupon_orderby'] ) : false );
						$export->coupon_order = ( isset( $_POST['coupon_order'] ) ? sanitize_text_field( $_POST['coupon_order'] ) : false );

						// Save dataset export specific options
						if( $export->coupon_orderby <> woo_ce_get_option( 'coupon_orderby' ) )
							woo_ce_update_option( 'coupon_orderby', $export->coupon_orderby );
						if( $export->coupon_order <> woo_ce_get_option( 'coupon_order' ) )
							woo_ce_update_option( 'coupon_order', $export->coupon_order );
						break;

					case 'subscription':
						// Set up dataset specific options

						// Save dataset export specific options
						$export->subscription_status = ( isset( $_POST['subscription_filter_status'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['subscription_filter_status'] ) ) : false );
						$export->subscription_product = ( isset( $_POST['subscription_filter_product'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['subscription_filter_product'] ) ) : false );
						break;

					case 'attribute':
						break;

					case 'product_vendor':
						break;

					case 'commission':
						$export->commission_dates_filter = ( isset( $_POST['commission_dates_filter'] ) ? sanitize_text_field( $_POST['commission_dates_filter'] ) : false );
						$export->commission_dates_from = sanitize_text_field( $_POST['commission_dates_from'] );
						$export->commission_dates_to = sanitize_text_field( $_POST['commission_dates_to'] );
						$export->commission_dates_filter_variable = ( isset( $_POST['commission_dates_filter_variable'] ) ? absint( $_POST['commission_dates_filter_variable'] ) : false );
						$export->commission_dates_filter_variable_length = ( isset( $_POST['commission_dates_filter_variable_length'] ) ? sanitize_text_field( $_POST['commission_dates_filter_variable_length'] ) : false );
						$export->commission_product_vendors = ( isset( $_POST['commission_filter_product_vendor'] ) ? woo_ce_format_product_filters( array_map( 'absint', $_POST['commission_filter_product_vendor'] ) ) : false );
						$export->commission_status = ( isset( $_POST['commission_filter_commission_status'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['commission_filter_commission_status'] ) ) : false );
						$export->commission_orderby = ( isset( $_POST['commission_orderby'] ) ? sanitize_text_field( $_POST['commission_orderby'] ) : false );
						$export->commission_order = ( isset( $_POST['commission_order'] ) ? sanitize_text_field( $_POST['commission_order'] ) : false );

						// Save dataset export specific options
						if( $export->commission_orderby <> woo_ce_get_option( 'commission_orderby' ) )
							woo_ce_update_option( 'commission_orderby', $export->commission_orderby );
						if( $export->commission_order <> woo_ce_get_option( 'commission_order' ) )
							woo_ce_update_option( 'commission_order', $export->commission_order );
						break;

					case 'shipping_class':
						// Set up dataset specific options
						$export->shipping_class_orderby = ( isset( $_POST['shipping_class_orderby'] ) ? sanitize_text_field( $_POST['shipping_class_orderby'] ) : false );
						$export->shipping_class_order = ( isset( $_POST['shipping_class_order'] ) ? sanitize_text_field( $_POST['shipping_class_order'] ) : false );

						// Save dataset export specific options
						if( $export->shipping_class_orderby <> woo_ce_get_option( 'shipping_class_orderby' ) )
							woo_ce_update_option( 'shipping_class_orderby', $export->shipping_class_orderby );
						if( $export->shipping_class_order <> woo_ce_get_option( 'shipping_class_order' ) )
							woo_ce_update_option( 'shipping_class_order', $export->shipping_class_order );
						break;

				}
				if( $export->type ) {

					$timeout = 600;
					if( isset( $_POST['timeout'] ) ) {
						$timeout = absint( $_POST['timeout'] );
						if( $timeout <> woo_ce_get_option( 'timeout' ) )
							woo_ce_update_option( 'timeout', $timeout );
					}
					if( !ini_get( 'safe_mode' ) )
						@set_time_limit( $timeout );

					@ini_set( 'memory_limit', WP_MAX_MEMORY_LIMIT );
					@ini_set( 'max_execution_time', $timeout );

					$export->args = array(
						'limit_volume' => $export->limit_volume,
						'offset' => $export->offset,
						'encoding' => $export->encoding,
						'date_format' => $export->date_format,
						'product_categories' => $export->product_categories,
						'product_tags' => $export->product_tags,
						'product_brands' => $export->product_brands,
						'product_vendors' => $export->product_vendors,
						'product_status' => $export->product_status,
						'product_type' => $export->product_type,
						'product_stock' => $export->product_stock,
						'product_language' => $export->product_language,
						'product_orderby' => $export->product_orderby,
						'product_order' => $export->product_order,
						'category_language' => $export->category_language,
						'category_orderby' => $export->category_orderby,
						'category_order' => $export->category_order,
						'tag_language' => $export->tag_language,
						'tag_orderby' => $export->tag_orderby,
						'tag_order' => $export->tag_order,
						'brand_orderby' => $export->brand_orderby,
						'brand_order' => $export->brand_order,
						'order_status' => $export->order_status,
						'order_dates_filter' => $export->order_dates_filter,
						'order_dates_from' => woo_ce_format_order_date( $export->order_dates_from ),
						'order_dates_to' => woo_ce_format_order_date( $export->order_dates_to ),
						'order_dates_filter_variable' => $export->order_dates_filter_variable,
						'order_dates_filter_variable_length' => $export->order_dates_filter_variable_length,
						'order_customer' => $export->order_customer,
						'order_billing_country' => $export->order_billing_country,
						'order_shipping_country' => $export->order_shipping_country,
						'order_user_roles' => $export->order_user_roles,
						'order_coupons' => $export->order_coupons,
						'order_product' => $export->order_product,
						'order_category' => $export->order_category,
						'order_tag' => $export->order_tag,
						'order_brand' => $export->order_brand,
						'order_ids' => $export->order_ids,
						'order_payment' => $export->order_payment,
						'order_shipping' => $export->order_shipping,
						'order_items' => $export->order_items,
						'order_items_types' => $export->order_items_types,
						'order_orderby' => $export->order_orderby,
						'order_order' => $export->order_order,
						'user_orderby' => $export->user_orderby,
						'user_order' => $export->user_order,
						'coupon_discount_types' => $export->coupon_discount_types,
						'coupon_orderby' => $export->coupon_orderby,
						'coupon_order' => $export->coupon_order,
						'subscription_status' => $export->subscription_status,
						'subscription_product' => $export->subscription_product,
						'commission_dates_filter' => $export->commission_dates_filter,
						'commission_dates_from' => woo_ce_format_order_date( $export->commission_dates_from ),
						'commission_dates_to' => woo_ce_format_order_date( $export->commission_dates_to ),
						'commission_dates_filter_variable' => $export->commission_dates_filter_variable,
						'commission_dates_filter_variable_length' => $export->commission_dates_filter_variable_length,
						'commission_product_vendors' => $export->commission_product_vendors,
						'commission_status' => $export->commission_status,
						'commission_orderby' => $export->commission_orderby,
						'commission_order' => $export->commission_order,
						'shipping_class_orderby' => $export->shipping_class_orderby,
						'shipping_class_order' => $export->shipping_class_order
					);

					if( empty( $export->fields ) ) {
						$message = __( 'No export fields were selected, please try again with at least a single export field.', 'woo_ce' );
						woo_cd_admin_notice( $message, 'error' );
						return;
					}
					woo_ce_save_fields( $export->type, $export->fields, $export->fields_order );
					unset( $export->fields_order );

					$export->filename = woo_ce_generate_filename( $export->type );

					$export->idle_memory_end = woo_ce_current_memory_usage();
					$export->end_time = time();

					// Let's spin up PHPExcel for supported Export Types and Export Formats
					if( in_array( $export->export_format, array( 'csv', 'xls', 'xlsx' ) ) ) {

						$dataset = woo_ce_export_dataset( $export->type );
						if( empty( $dataset ) ) {
							$message = __( 'No export entries were found, please try again with different export filters.', 'woo_ce' );
							woo_cd_admin_notice( $message, 'error' );
							return;
						}

						// Load up the fatal error notice if we 500, timeout or encounter a fatal PHP error
						add_action( 'shutdown', 'woo_ce_fatal_error' );

						// Check that PHPExcel is where we think it is
						if( file_exists( WOO_CD_PATH . 'classes/PHPExcel.php' ) ) {
							// Check if PHPExcel has already been loaded
							if( !class_exists( 'PHPExcel' ) ) {
								include_once( WOO_CD_PATH . 'classes/PHPExcel.php' );
							} else {
								$message = sprintf( __( 'The PHPExcel library was already loaded by another WordPress Plugin, if there\'s issues with your export file you know where to look. <a href="%s" target="_blank">Need help?</a>', 'woo_ce' ), $troubleshooting_url );
								woo_cd_admin_notice( $message, 'error' );
							}
						} else {
							$message = sprintf( __( 'We couldn\'t load the PHPExcel library <code>%s</code> within <code>%s</code>, this file should be present. <a href="%s" target="_blank">Need help?</a>', 'woo_ce' ), 'PHPExcel.php', WOO_CD_PATH . 'classes/...', $troubleshooting_url );
							woo_cd_admin_notice( $message, 'error' );
							return;
						}

						$excel = new PHPExcel();
						$excel->setActiveSheetIndex( 0 );
						$excel->getActiveSheet()->setTitle( ucfirst( $export->type ) );

						$row = 1;
						// Skip headers if Heading Formatting is turned off
						if( $export->header_formatting ) {
							$col = 0;
							foreach( $export->columns as $column ) {
								$excel->getActiveSheet()->setCellValueByColumnAndRow( $col, $row, $column );
								$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->getStyle()->getFont()->setBold( true );
								$excel->getActiveSheet()->getColumnDimensionByColumn( $col )->setAutoSize( true );
								$col++;
							}
							$row = 2;
						}
						$col = 0;
						foreach( $dataset as $data ) {
							$col = 0;
							foreach( array_keys( $export->fields ) as $field ) {
								$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->getStyle()->getFont()->setBold( false );
								if( $export->encoding == 'UTF-8' ) {
									if( woo_ce_detect_value_string( ( isset( $data->$field ) ? $data->$field : null ) ) ) {
										// Treat this cell as a string
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValueExplicit( ( isset( $data->$field ) ? wp_specialchars_decode( $data->$field ) : '' ), PHPExcel_Cell_DataType::TYPE_STRING );
									} else {
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValue( ( isset( $data->$field ) ? wp_specialchars_decode( $data->$field ) : '' ) );
									}
								} else {
									// PHPExcel only deals with UTF-8 regardless of encoding type
									if( woo_ce_detect_value_string( ( isset( $data->$field ) ? $data->$field : null ) ) ) {
										// Treat this cell as a string
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValueExplicit( ( isset( $data->$field ) ? utf8_encode( wp_specialchars_decode( $data->$field ) ) : '' ), PHPExcel_Cell_DataType::TYPE_STRING );
									} else {
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValue( ( isset( $data->$field ) ? utf8_encode( wp_specialchars_decode( $data->$field ) ) : '' ) );
									}
								}
								$col++;
							}
							$row++;
						}
						// Override the export format to CSV if debug mode is enabled
						if( WOO_CD_DEBUG )
							$export->export_format = 'csv';
						switch( $export->export_format ) {

							case 'csv':
								woo_cd_load_phpexcel_sed_csv_writer();
								$php_excel_format = 'SED_CSV';
								$file_extension = 'csv';
								$post_mime_type = 'text/csv';
								break;

							case 'xls':
								$php_excel_format = 'Excel5';
								$file_extension = 'xls';
								$post_mime_type = 'application/vnd.ms-excel';
								break;

							case 'xlsx':
								$php_excel_format = 'Excel2007';
								$file_extension = 'xlsx';
								$post_mime_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
								break;

						}
						$export->filename = $export->filename . '.' . $file_extension;
						$objWriter = PHPExcel_IOFactory::createWriter( $excel, $php_excel_format );

						// Only write headers if we're not in debug mode
						if( WOO_CD_DEBUG !== true ) {

							// Print to browser
							woo_ce_generate_file_headers( $post_mime_type );
							switch( $export->export_format ) {
	
								case 'csv':
									$objWriter->setUseBOM( true );
									// Check if we're using a non-standard delimiter
									if( $export->delimiter != ',' )
										$objWriter->setDelimiter( $export->delimiter );
									break;

								case 'xlsx':
									$objWriter->setPreCalculateFormulas( false );
									break;

							}
							// Print directly to browser, do not save
							if( $export->delete_file ) {
								// The end memory usage and time is collected at the very last opportunity prior to the file header being rendered to the screen
								woo_ce_update_file_detail( $post_ID, '_woo_idle_memory_end', woo_ce_current_memory_usage() );
								woo_ce_update_file_detail( $post_ID, '_woo_end_time', time() );
								delete_option( WOO_CD_PREFIX . '_exported' );
								$objWriter->save( 'php://output' );
							} else {
								// Save to file and insert to WordPress Media
								$temp_filename = tempnam( apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ), 'tmp' );
								// Check if we were given a temporary filename
								if( $temp_filename == false ) {
									$message = sprintf( __( 'We could not create a temporary export file in <code>%s</code>, ensure that WordPress can read and write files here and try again.', 'woo_ce' ), apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ) );
									woo_cd_admin_notice( $message, 'error' );
									wp_redirect( esc_url( add_query_arg( array( 'failed' => true, 'message' => urlencode( $message ) ) ) ) );
									exit();
								} else {
									$objWriter->save( $temp_filename );
									$bits = file_get_contents( $temp_filename );
								}
								unlink( $temp_filename );

								$post_ID = woo_ce_save_file_attachment( $export->filename, $post_mime_type );
								$upload = wp_upload_bits( $export->filename, null, $bits );
								// Check if the upload succeeded otherwise delete Post and return error notice
								if( ( $post_ID == false ) || $upload['error'] ) {
									wp_delete_attachment( $post_ID, true );
									if( isset( $upload['error'] ) )
										wp_redirect( esc_url( add_query_arg( array( 'failed' => true, 'message' => urlencode( $upload['error'] ) ) ) ) );
									else
										wp_redirect( esc_url( add_query_arg( array( 'failed' => true ) ) ) );
									return;
								}
								if( file_exists( ABSPATH . 'wp-admin/includes/image.php' ) ) {
									$attach_data = wp_generate_attachment_metadata( $post_ID, $upload['file'] );
									wp_update_attachment_metadata( $post_ID, $attach_data );
									update_attached_file( $post_ID, $upload['file'] );
									if( !empty( $post_ID ) ) {
										woo_ce_save_file_guid( $post_ID, $export->type, $upload['url'] );
										woo_ce_save_file_details( $post_ID );
									}
								} else {
									error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'Could not load image.php within /wp-admin/includes/image.php', 'woo_ce' ) ) );
								}
								// The end memory usage and time is collected at the very last opportunity prior to the file header being rendered to the screen
								woo_ce_update_file_detail( $post_ID, '_woo_idle_memory_end', woo_ce_current_memory_usage() );
								woo_ce_update_file_detail( $post_ID, '_woo_end_time', time() );
								delete_option( WOO_CD_PREFIX . '_exported' );
								$objWriter->save( 'php://output' );

							}

							// Clean up PHPExcel
							$excel->disconnectWorksheets();
							unset( $objWriter, $excel );
							exit();

						} else {

							// Save to temporary file then dump into export log screen
							$objWriter->setUseBOM( true );
							$temp_filename = tempnam( apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ), 'tmp' );
							// Check if we were given a temporary filename
							if( $temp_filename == false ) {
								$message = sprintf( __( 'We could not create a temporary export file in <code>%s</code>, ensure that WordPress can read and write files here and try again.', 'woo_ce' ), apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ) );
								woo_cd_admin_notice( $message, 'error' );
							} else {
								$objWriter->save( $temp_filename );
								$bits = file_get_contents( $temp_filename );
							}
							unlink( $temp_filename );

							// Clean up PHPExcel
							$excel->disconnectWorksheets();
							unset( $objWriter, $excel );

							// Save the export contents to the WordPress Transient
							$response = set_transient( WOO_CD_PREFIX . '_debug_log', base64_encode( $bits ), 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>)';
								woo_cd_admin_notice( $message, 'error' );
							}

						}

						// Remove our fatal error notice to play nice with other Plugins
						remove_action( 'shutdown', 'woo_ce_fatal_error' );

					// Run the default engine for the XML and RSS export formats
					} else if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) {

						// Check if SimpleXMLElement is present
						if( !class_exists( 'SED_SimpleXMLElement' ) ) {
							$message = sprintf( __( 'We couldn\'t load the SimpleXMLElement class, the SimpleXMLElement class is required for XML and RSS feed generation. <a href="%s" target="_blank">Need help?</a>', 'woo_ce' ), $troubleshooting_url );
							woo_cd_admin_notice( $message, 'error' );
							return;
						}

						switch( $export->export_format ) {

							case 'xml':
								$file_extension = 'xml';
								$post_mime_type = 'application/xml';
								break;

							case 'rss':
								$file_extension = 'xml';
								$post_mime_type = 'application/rss+xml';
								break;

						}
						$export->filename = $export->filename . '.' . $file_extension;

						if( $export->export_format == 'xml' ) {
							$xml = new SED_SimpleXMLElement( sprintf( apply_filters( 'woo_ce_export_xml_first_line', '<?xml version="1.0" encoding="%s"?><%s/>' ), esc_attr( $export->encoding ), esc_attr( apply_filters( 'woo_ce_export_xml_store_node', 'store' ) ) ) );
							if( woo_ce_get_option( 'xml_attribute_url', 1 ) )
								$xml->addAttribute( 'url', get_site_url() );
							if( woo_ce_get_option( 'xml_attribute_date', 1 ) )
								$xml->addAttribute( 'date', date( 'Y-m-d' ) );
							if( woo_ce_get_option( 'xml_attribute_time', 0 ) )
								$xml->addAttribute( 'time', date( 'H:i:s' ) );
							if( woo_ce_get_option( 'xml_attribute_title', 1 ) )
								$xml->addAttribute( 'name', htmlspecialchars( get_bloginfo( 'name' ) ) );
							if( woo_ce_get_option( 'xml_attribute_export', 1 ) )
								$xml->addAttribute( 'export', htmlspecialchars( $export->type ) );
							if( woo_ce_get_option( 'xml_attribute_orderby', 1 ) && isset( $export->{$export->type . '_orderby'} ) )
								$xml->addAttribute( 'orderby', $export->{$export->type . '_orderby'} );
							if( woo_ce_get_option( 'xml_attribute_order', 1 ) && isset( $export->{$export->type . '_order'} ) )
								$xml->addAttribute( 'order', $export->{$export->type . '_order'} );
							if( woo_ce_get_option( 'xml_attribute_limit', 1 ) )
								$xml->addAttribute( 'limit', $export->limit_volume );
							if( woo_ce_get_option( 'xml_attribute_offset', 1 ) )
								$xml->addAttribute( 'offset', $export->offset );
							$bits = woo_ce_export_dataset( $export->type, $xml );
						} else if( $export->export_format == 'rss' ) {
							$xml = new SED_SimpleXMLElement( sprintf( apply_filters( 'woo_ce_export_rss_first_line', '<?xml version="1.0" encoding="%s"?><rss version="2.0"%s/>' ), esc_attr( $export->encoding ), ' xmlns:g="http://base.google.com/ns/1.0"' ) );
							$child = $xml->addChild( apply_filters( 'woo_ce_export_rss_channel_node', 'channel' ) );
							$child->addChild( 'title', woo_ce_get_option( 'rss_title', '' ) );
							$child->addChild( 'link', woo_ce_get_option( 'rss_link', '' ) );
							$child->addChild( 'description', woo_ce_get_option( 'rss_description', '' ) );
							$bits = woo_ce_export_dataset( $export->type, $child );
						}

						if( empty( $bits ) ) {
							$message = __( 'No export entries were found, please try again with different export filters.', 'woo_ce' );
							woo_cd_admin_notice( $message, 'error' );
							return;
						}

						if( WOO_CD_DEBUG !== true ) {
							if( $export->delete_file ) {

								// Print directly to browser
								woo_ce_generate_file_headers( $post_mime_type );
								if( $bits = woo_ce_format_xml( $bits ) )
									echo $bits;
								exit();

							} else {

								// Save to file and insert to WordPress Media
								if( $export->filename && $bits ) {
									$post_ID = woo_ce_save_file_attachment( $export->filename, $post_mime_type );
									$bits = woo_ce_format_xml( $bits );
									$upload = wp_upload_bits( $export->filename, null, $bits );
									// Check for issues saving to WordPress Media
									if( ( $post_ID == false ) || !empty( $upload['error'] ) ) {
										wp_delete_attachment( $post_ID, true );
										if( isset( $upload['error'] ) )
											wp_redirect( esc_url( add_query_arg( array( 'failed' => true, 'message' => urlencode( $upload['error'] ) ) ) ) );
										else
											wp_redirect( esc_url( add_query_arg( array( 'failed' => true ) ) ) );
										return;
									}
									$attach_data = wp_generate_attachment_metadata( $post_ID, $upload['file'] );
									wp_update_attachment_metadata( $post_ID, $attach_data );
									update_attached_file( $post_ID, $upload['file'] );
									if( $post_ID ) {
										woo_ce_save_file_guid( $post_ID, $export->type, $upload['url'] );
										woo_ce_save_file_details( $post_ID );
									}
									$export_type = $export->type;
									unset( $export );

									// The end memory usage and time is collected at the very last opportunity prior to the XML header being rendered to the screen
									woo_ce_update_file_detail( $post_ID, '_woo_idle_memory_end', woo_ce_current_memory_usage() );
									woo_ce_update_file_detail( $post_ID, '_woo_end_time', time() );
									delete_option( WOO_CD_PREFIX . '_exported' );

									// Generate XML header
									woo_ce_generate_file_headers( $post_mime_type );
									unset( $export_type );

									// Print file contents to screen
									if( !empty( $upload['file'] ) ) {
										// Check if readfile() is disabled on this host
										$disabled = explode( ',', ini_get( 'disable_functions' ) );
										if( !in_array( 'readfile', $disabled ) ) {
											readfile( $upload['file'] );
										} else {
											// Workaround for disabled readfile on some hosts
											$fp = fopen( $upload['file'], 'rb' );
											fpassthru( $fp );
											fclose( $fp );
											unset( $fp );
										}
										unset( $disabled );
									} else {
										wp_redirect( esc_url( add_query_arg( 'failed', true ) ) );
									}
									unset( $upload );
								} else {
									wp_redirect( esc_url( add_query_arg( 'failed', true ) ) );
								}
								exit();

							}
						}

					}

				}
				break;

			// Save changes on Settings screen
			case 'save-settings':
				woo_ce_admin_save_settings();
				break;

			// Save changes on Field Editor screen
			case 'save-fields':
				$fields = ( isset( $_POST['fields'] ) ? array_filter( $_POST['fields'] ) : array() );
				$hidden = ( isset( $_POST['hidden'] ) ? array_filter( $_POST['hidden'] ) : array() );
				$export_type = ( isset( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : '' );
				$types = array_keys( woo_ce_return_export_types() );
				// Check we are saving against a valid export type
				if( in_array( $export_type, $types ) ) {
					woo_ce_update_option( $export_type . '_labels', $fields );
					woo_ce_update_option( $export_type . '_hidden', $hidden );
					$message = __( 'Changes have been saved.', 'woo_ce' );
					woo_cd_admin_notice( $message );
				} else {
					$message = __( 'Changes could not be saved as we could not detect a valid export type. Raise this as a Premium Support issue and include what export type you were editing.', 'woo_ce' );
					woo_cd_admin_notice( $message, 'error' );
				}
				break;

		}

	}
コード例 #4
0
function woo_ce_cron_export( $gui = '', $type = '', $is_scheduled = false ) {

	global $export;

	$export = new stdClass;
	$export->cron = ( $is_scheduled ? 0 : 1 );
	$export->scheduled_export = ( $is_scheduled ? 1 : 0 );
	$export->start_time = time();
	$export->idle_memory_start = woo_ce_current_memory_usage();
	$export->error = '';

	$bits = '';
	$type = ( isset( $_GET['type'] ) ? $_GET['type'] : $type );
	if( empty( $type ) ) {
		if( $gui == 'gui' ) {
			$output = sprintf( '<p>%s</p>', __( 'No export type was provided.', 'woo_ce' ) );
		} else {
			error_log( sprintf( '[store-exporter-deluxe] -: Error: %s', __( 'No export type was provided', 'woo_ce' ) ) );
			return false;
		}
	} else {
		$types = array_keys( woo_ce_return_export_types() );
		$export->type = $type;
		// Check that export is in the list of available exports
		if( !in_array( $export->type, $types ) ) {
			if( $gui == 'gui' ) {
				$output = '<p>' . __( 'An invalid export type was provided.', 'woo_ce' ) . '</p>';
			} else {
				error_log( sprintf( '[store-exporter-deluxe] -: Error: %s', __( 'An invalid export type was provided', 'woo_ce' ) ) );
				return false;
			}
		} else {
			$export->export_format = ( isset( $_GET['format'] ) ? sanitize_text_field( $_GET['format'] ) : woo_ce_get_option( 'export_format', 'csv' ) );

			// Override the export format if outputting to screen in friendly design
			if( $gui == 'gui' && in_array( $export->export_format, array( 'csv', 'xls', 'xlsx' ) ) )
				$export->export_format = 'csv';

			// Override the export format if this is a scheduled export
			if( $export->scheduled_export )
				$export->export_format = woo_ce_get_option( 'auto_format', 'csv' );

			// Override the export format if the single order Transient is set
			$single_export_format = get_transient( WOO_CD_PREFIX . '_single_export_format' );
			if( $single_export_format !== false )
				$export->export_format = $single_export_format;
			unset( $single_export_format );

			$export->delimiter = ( isset( $_GET['delimiter'] ) ? sanitize_text_field( $_GET['delimiter'] ) : woo_ce_get_option( 'delimiter', ',' ) );
			if( $export->delimiter == '' || $export->delimiter == false ) {
				error_log( '[store-exporter-deluxe] Warning: Delimiter export option was corrupted, defaulted to ,' );
				$export->delimiter = ',';
				woo_ce_update_option( 'delimiter', ',' );
			} else if( $export->delimiter == 'TAB' ) {
				$export->delimiter = "\t";
			}
			$export->category_separator = ( isset( $_GET['category_separator'] ) ? sanitize_text_field( $_GET['category_separator'] ) : woo_ce_get_option( 'category_separator', '|' ) );
			// Override for line break (LF) support in Category Separator
			if( $export->category_separator == 'LF' )
				$export->category_separator = "\n";
			$export->bom = ( isset( $_GET['bom'] ) ? absint( $_GET['bom'] ) : woo_ce_get_option( 'bom', 1 ) );
			$export->encoding = ( isset( $_GET['encoding'] ) ? sanitize_text_field( $_GET['encoding'] ) : woo_ce_get_option( 'encoding', 'UTF-8' ) );
			$export->timeout = woo_ce_get_option( 'timeout', 600 );
			$export->escape_formatting = ( isset( $_GET['escape_formatting'] ) ? sanitize_text_field( $_GET['escape_formatting'] ) : woo_ce_get_option( 'escape_formatting', 'all' ) );
			$export->header_formatting = ( isset( $_GET['header_formatting'] ) ? absint( $_GET['header_formatting'] ) : woo_ce_get_option( 'header_formatting', 1 ) );
			$export->date_format = woo_ce_get_option( 'date_format', 'd/m/Y' );
			$export->order_items = ( isset( $_GET['order_items'] ) ? sanitize_text_field( $_GET['order_items'] ) : woo_ce_get_option( 'order_items_formatting', 'unique' ) );
			$export->order_items_types = ( isset( $_GET['order_items_types'] ) ? sanitize_text_field( $_GET['order_items_types'] ) : woo_ce_get_option( 'order_items_types', false ) );
			$export->upsell_formatting = woo_ce_get_option( 'upsell_formatting', 1 );
			$export->crosssell_formatting = woo_ce_get_option( 'crosssell_formatting', 1 );
			$export->gallery_formatting = woo_ce_get_option( 'gallery_formatting', 0 );
			$export->gallery_unique = woo_ce_get_option( 'gallery_unique', 0 );
			$export->max_product_gallery = woo_ce_get_option( 'max_product_gallery', 3 );
			$export->filename = woo_ce_generate_filename( $export->type );
			switch( $export->export_format ) {

				case 'csv':
					$php_excel_format = 'SED_CSV';
					$file_extension = 'csv';
					$post_mime_type = 'text/csv';
					break;

				case 'xls':
					$php_excel_format = 'Excel5';
					$file_extension = 'xls';
					$post_mime_type = 'application/vnd.ms-excel';
					break;

				case 'xlsx':
					$php_excel_format = 'Excel2007';
					$file_extension = 'xlsx';
					$post_mime_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
					break;

				case 'xml':
					$file_extension = 'xml';
					$post_mime_type = 'application/xml';
					break;

				case 'rss':
					$file_extension = 'xml';
					$post_mime_type = 'application/rss+xml';
					break;

				default:
					error_log( sprintf( '[store-exporter-deluxe] -: Warning: %s', __( 'An invalid export format was provided', 'woo_ce' ) ) );
					return;
					break;

			}
			$export->filename = $export->filename . '.' . $file_extension;
			$export->limit_volume = ( isset( $_GET['limit'] ) ? absint( $_GET['limit'] ) : -1 );
			$export->offset = ( isset( $_GET['offset'] ) ? absint( $_GET['offset'] ) : 0 );
			// Select all export fields for CRON export
			$export->fields = woo_ce_cron_export_fields( $export->type, $export->scheduled_export );
			// Grab to value if response is e-mail or remote POST
			if( in_array( $gui, array( 'email', 'post' ) ) ) {
				if( $gui == 'email' )
					$export->to = ( isset( $_GET['to'] ) ? sanitize_email( $_GET['to'] ) : woo_ce_get_option( 'email_to', '' ) );
				else if( $gui == 'post' )
					$export->to = ( isset( $_GET['to'] ) ? esc_url_raw( $_GET['to'] ) : woo_ce_get_option( 'post_to', '' ) );
			}
			$export = woo_ce_check_cron_export_arguments( $export );

			$export->args = array(
				'limit_volume' => $export->limit_volume,
				'offset' => $export->offset,
				'encoding' => $export->encoding,
				'date_format' => $export->date_format,
				'order_items' => $export->order_items,
				'order_items_types' => $export->order_items_types
			);

			$orderby = ( isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : null );
			$order = ( isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : null );
			switch( $export->type ) {

				case 'product':
					$export->args['product_orderby'] = $orderby;
					$export->args['product_order'] = $order;
					if( $export->scheduled_export ) {
						$product_filter_type = woo_ce_get_option( 'auto_product_type', false );
						$product_filter_status = woo_ce_get_option( 'auto_product_status', false );
						$product_filter_stock = woo_ce_get_option( 'auto_product_stock', false );
						$product_filter_category = woo_ce_get_option( 'auto_product_category', false );
						$product_filter_tag = woo_ce_get_option( 'auto_product_tag', false );
						$export->args['product_type'] = ( !empty( $product_filter_type ) ? $product_filter_type : false );
						$export->args['product_status'] = ( !empty( $product_filter_status ) ? $product_filter_status : false );
						$export->args['product_stock'] = ( !empty( $product_filter_stock ) ? $product_filter_stock : false );
						$export->args['product_categories'] = ( !empty( $product_filter_category ) ? $product_filter_category : false );
						$export->args['product_tags'] = ( !empty( $product_filter_tag ) ? $product_filter_tag : false );
					} else {
						$export->args['product_status'] = ( isset( $_GET['product_status'] ) ? sanitize_text_field( $_GET['product_status'] ) : null );
						$export->args['product_stock'] = ( isset( $_GET['stock_status'] ) ? sanitize_text_field( $_GET['stock_status'] ) : null );
					}
					break;

				case 'category':
					$export->args['category_orderby'] = $orderby;
					$export->args['category_order'] = $order;
					break;

				case 'tag':
					$export->args['tag_orderby'] = $orderby;
					$export->args['tag_order'] = $order;
					break;

				case 'order':
					$export->args['order_orderby'] = $orderby;
					$export->args['order_order'] = $order;
					$export->args['order_ids'] = ( isset( $_GET['order_ids'] ) ? sanitize_text_field( $_GET['order_ids'] ) : null );

					// Override Filter Orders by Order ID if a single order transient is set
					$single_export_order_ids = get_transient( WOO_CD_PREFIX . '_single_export_order_ids' );
					if( $single_export_order_ids !== false )
						$export->args['order_ids'] = sanitize_text_field( $single_export_order_ids );
					unset( $single_export_order_ids );

					if( $export->scheduled_export ) {

						// Scheduled export engine

						// Order Status
						$order_filter_status = woo_ce_get_option( 'auto_order_status', '' );
						$export->args['order_status'] = ( !empty( $order_filter_status ) ? (array)$order_filter_status : array() );
						// Order Date
						$order_dates_filter = woo_ce_get_option( 'auto_order_date', false );
						if( $order_dates_filter ) {
							$export->args['order_dates_filter'] = $order_dates_filter;
							switch( $order_dates_filter ) {

								case 'manual':
									$order_filter_dates_from = woo_ce_get_option( 'auto_order_dates_from', false );
									$order_filter_dates_to = woo_ce_get_option( 'auto_order_dates_to', false );
									$export->args['order_dates_from'] = ( !empty( $order_filter_dates_from ) ? sanitize_text_field( $order_filter_dates_from ) : false );
									$export->args['order_dates_to'] = ( !empty( $order_filter_dates_to ) ? sanitize_text_field( $order_filter_dates_to ) : false );
									break;

								case 'variable':
									$order_filter_date_variable = woo_ce_get_option( 'auto_order_date_variable', false );
									$order_filter_date_variable_length = woo_ce_get_option( 'auto_order_date_variable_length', false );
									$export->args['order_dates_filter_variable'] = ( !empty( $order_filter_date_variable ) ? absint( $order_filter_date_variable ) : false );
									$export->args['order_dates_filter_variable_length'] = ( !empty( $order_filter_date_variable_length ) ? sanitize_text_field( $order_filter_date_variable_length ) : false );
									break;

							}
						}
						// Product
						$order_filter_product = woo_ce_get_option( 'auto_order_product', '' );
						$export->args['order_product'] = ( !empty( $order_filter_product ) ? (array)$order_filter_product : array() );
						// Billing Country
						$order_filter_billing_country = woo_ce_get_option( 'auto_order_billing_country', false );
						$export->args['order_billing_country'] = ( !empty( $order_filter_billing_country ) ? array_map( 'sanitize_text_field', $order_filter_billing_country ) : false );
						// Shipping Country
						$order_filter_shipping_country = woo_ce_get_option( 'auto_order_shipping_country', false );
						$export->args['order_shipping_country'] = ( !empty( $order_filter_shipping_country ) ? array_map( 'sanitize_text_field', $order_filter_shipping_country ) : false );
						// Payment Gateway
						$order_filter_payment = woo_ce_get_option( 'auto_order_payment', array() );
						$export->args['order_payment'] = ( !empty( $order_filter_payment ) ? array_map( 'sanitize_text_field', $order_filter_payment ) : false );
						// Shipping Method
						$order_filter_shipping = woo_ce_get_option( 'auto_order_shipping', array() );
						$export->args['order_shipping'] = ( !empty( $order_filter_shipping ) ? array_map( 'sanitize_text_field', $order_filter_shipping ) : false );
					} else {

						// CRON export engine

						// Order Status
						if( isset( $_GET['order_status'] ) ) {
							$order_filter_status = sanitize_text_field( $_GET['order_status'] );
							$order_filter_status = explode( ',', $order_filter_status );
							$export->args['order_status'] = $order_filter_status;
						}
						// Product
						if( isset( $_GET['order_product'] ) ) {
							$order_filter_product = sanitize_text_field( $_GET['order_product'] );
							$order_filter_product = explode( ',', $order_filter_product );
							$export->args['order_product'] = $order_filter_product;
						}
						// Order Date
						if( isset( $_GET['order_date_from'] ) && isset( $_GET['order_date_to'] ) ) {
							$order_filter_dates_from = $_GET['order_date_from'];
							$order_filter_dates_to = $_GET['order_date_to'];
							$export->args['order_dates_filter'] = 'manual';
							$export->args['order_dates_from'] = ( !empty( $order_filter_dates_from ) ? sanitize_text_field( $order_filter_dates_from ) : false );
							$export->args['order_dates_to'] = ( !empty( $order_filter_dates_to ) ? sanitize_text_field( $order_filter_dates_to ) : false );
						}
						// Billing Country
						if( isset( $_GET['billing_country'] ) ) {
							$order_filter_billing_country = sanitize_text_field( $_GET['billing_country'] );
							$order_filter_billing_country = explode( ',', $order_filter_billing_country );
							$export->args['order_billing_country'] = ( !empty( $order_filter_billing_country ) ? $order_filter_billing_country : false );
						}
						// Shipping Country
						if( isset( $_GET['shipping_country'] ) ) {
							$order_filter_shipping_country = sanitize_text_field( $_GET['shipping_country'] );
							$order_filter_shipping_country = explode( ',', $order_filter_shipping_country );
							$export->args['order_shipping_country'] = ( !empty( $order_filter_shipping_country ) ? $order_filter_shipping_country : false );
						}
						// Payment Gateway
						if( isset( $_GET['payment_gateway'] ) ) {
							$order_filter_payment = sanitize_text_field( $_GET['order_payment'] );
							$order_filter_payment = explode( ',', $order_filter_payment );
							$export->args['order_payment'] = ( !empty( $order_filter_payment ) ? $order_filter_payment : false );
						}
						// Shipping Method
						if( isset( $_GET['shipping_method'] ) ) {
							$order_filter_shipping = sanitize_text_field( $_GET['shipping_method'] );
							$order_filter_shipping = explode( ',', $order_filter_shipping );
							$export->args['order_shipping'] = ( !empty( $order_filter_shipping ) ? $order_filter_shipping : false );
						}
					}
					break;

				case 'subscription':
					$export->args['subscription_orderby'] = $orderby;
					$export->args['subscription_order'] = $order;
					break;

				case 'product_vendor':
					$export->args['product_vendor_orderby'] = $orderby;
					$export->args['product_vendor_order'] = $order;
					break;

				case 'commission':
					// Commission Date
					$commission_dates_filter = woo_ce_get_option( 'auto_commission_date', false );
					if( $commission_dates_filter ) {
						$export->args['commission_dates_filter'] = $commission_dates_filter;
						switch( $commission_dates_filter ) {

							case 'manual':
								$commission_filter_dates_from = woo_ce_get_option( 'auto_commission_dates_from', false );
								$commission_filter_dates_to = woo_ce_get_option( 'auto_commission_date_to', false );
								$export->args['commission_dates_from'] = ( !empty( $commission_filter_dates_from ) ? sanitize_text_field( $commission_filter_dates_from ) : false );
								$export->args['commission_dates_to'] = ( !empty( $commission_filter_dates_to ) ? sanitize_text_field( $commission_filter_dates_to ) : false );
								break;

							case 'variable':
								$commission_filter_date_variable = woo_ce_get_option( 'auto_commission_date_variable', false );
								$commission_filter_date_variable_length = woo_ce_get_option( 'auto_commission_date_variable_length', false );
								$export->args['commission_dates_filter_variable'] = ( !empty( $commission_filter_date_variable ) ? absint( $commission_filter_date_variable ) : false );
								$export->args['commission_dates_filter_variable_length'] = ( !empty( $commission_filter_date_variable_length ) ? sanitize_text_field( $commission_filter_date_variable_length ) : false );
								break;

						}
					}
					break;

				case 'shipping_class':
					$export->args['shipping_class_orderby'] = $orderby;
					$export->args['shipping_class_order'] = $order;
					break;

			}
			$export->filename = woo_ce_generate_filename( $export->type ) . '.' . $file_extension;
			// Let's spin up PHPExcel for supported Export Types and Export Formats
			if( in_array( $export->export_format, array( 'csv', 'xls', 'xlsx' ) ) ) {
				// Check if we are using PHPExcel or not for supported Export Types
				$dataset = woo_ce_export_dataset( $export->type );
				if( !empty( $dataset ) ) {
					// Check that PHPExcel is where we think it is
					if( file_exists( WOO_CD_PATH . 'classes/PHPExcel.php' ) ) {
						// Check if PHPExcel has already been loaded
						if( !class_exists( 'PHPExcel' ) ) {
							include_once( WOO_CD_PATH . 'classes/PHPExcel.php' );
						} else {
							error_log( sprintf( '[store-exporter-deluxe] %s: Warning: %s', $export->filename, __( 'The PHPExcel library was already loaded by another WordPress Plugin, if there\'s issues with your export file you know where to look.', 'woo_ce' ) ) );
						}
						$excel = new PHPExcel();
						$excel->setActiveSheetIndex( 0 );
						$excel->getActiveSheet()->setTitle( ucfirst( $export->type ) );
						$row = 1;
						// Skip headers if Heading Formatting is turned off
						if( $export->header_formatting ) {
							$col = 0;
							foreach( $export->columns as $column ) {
								$excel->getActiveSheet()->setCellValueByColumnAndRow( $col, $row, $column );
								$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->getStyle()->getFont()->setBold( true );
								$excel->getActiveSheet()->getColumnDimensionByColumn( $col )->setAutoSize( true );
								$col++;
							}
							$row = 2;
						}
						foreach( $dataset as $data ) {
							$col = 0;
							foreach( array_keys( $export->fields ) as $field ) {
								$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->getStyle()->getFont()->setBold( false );
								if( $export->encoding == 'UTF-8' ) {
									if( woo_ce_detect_value_string( ( isset( $data->$field ) ? $data->$field : null ) ) ) {
										// Treat this cell as a string
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValueExplicit( ( isset( $data->$field ) ? wp_specialchars_decode( $data->$field ) : '' ), PHPExcel_Cell_DataType::TYPE_STRING );
									} else {
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValue( ( isset( $data->$field ) ? wp_specialchars_decode( $data->$field ) : '' ) );
									}
								} else {
									// PHPExcel only deals with UTF-8 regardless of encoding type
									if( woo_ce_detect_value_string( ( isset( $data->$field ) ? $data->$field : null ) ) ) {
										// Treat this cell as a string
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValueExplicit( ( isset( $data->$field ) ? utf8_encode( wp_specialchars_decode( $data->$field ) ) : '' ), PHPExcel_Cell_DataType::TYPE_STRING );
									} else {
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValue( ( isset( $data->$field ) ? utf8_encode( wp_specialchars_decode( $data->$field ) ) : '' ) );
									}
								}
								$col++;
							}
							$row++;
						}
						switch( $export->export_format ) {

							case 'csv':
								// We need to load this after the PHPExcel Class has been created
								woo_cd_load_phpexcel_sed_csv_writer();
								break;

						}
						$objWriter = PHPExcel_IOFactory::createWriter( $excel, $php_excel_format );
						switch( $export->export_format ) {

							case 'csv':
								$objWriter->setUseBOM( true );
								// Check if we're using a non-standard delimiter
								if( $export->delimiter != ',' )
									$objWriter->setDelimiter( $export->delimiter );
								break;

							case 'xlsx':
								$objWriter->setPreCalculateFormulas( false );
								break;

						}
						if( in_array( $gui, array( 'raw' ) ) ) {
							$objWriter->save( 'php://output' );
						} else {
							// Save to file and insert to WordPress Media
							$temp_filename = tempnam( apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ), 'tmp' );
							// Check if we were given a temporary filename
							if( $temp_filename == false ) {
								$message = sprintf( __( 'We could not create a temporary export file in %s, ensure that WordPress can read and write files here and try again.', 'woo_ce' ), apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ) );
								error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $message ) );
							} else {
								$objWriter->save( $temp_filename );
								$bits = file_get_contents( $temp_filename );
							}
							unlink( $temp_filename );
						}

						// Clean up PHPExcel
						$excel->disconnectWorksheets();
						unset( $objWriter, $excel );

					} else {
						error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'We couldn\'t load the PHPExcel library, this file should be present.' ) ) );
					}
				}
			// Run the default engine for the XML and RSS export formats
			} else if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) {
				// Check if SimpleXMLElement is present
				if( class_exists( 'SED_SimpleXMLElement' ) ) {
					if( $export->export_format == 'xml' ) {
						$xml = new SED_SimpleXMLElement( sprintf( apply_filters( 'woo_ce_export_xml_first_line', '<?xml version="1.0" encoding="%s"?><%s/>' ), esc_attr( $export->encoding ), esc_attr( apply_filters( 'woo_ce_export_xml_store_node', 'store' ) ) ) );
						if( woo_ce_get_option( 'xml_attribute_url', 1 ) )
							$xml->addAttribute( 'url', get_site_url() );
						if( woo_ce_get_option( 'xml_attribute_date', 1 ) )
							$xml->addAttribute( 'date', date( 'Y-m-d' ) );
						if( woo_ce_get_option( 'xml_attribute_time', 0 ) )
							$xml->addAttribute( 'time', date( 'H:i:s' ) );
						if( woo_ce_get_option( 'xml_attribute_title', 1 ) )
							$xml->addAttribute( 'name', htmlspecialchars( get_bloginfo( 'name' ) ) );
						if( woo_ce_get_option( 'xml_attribute_export', 1 ) )
							$xml->addAttribute( 'export', htmlspecialchars( $export->type ) );
						if( woo_ce_get_option( 'xml_attribute_orderby', 1 ) )
							$xml->addAttribute( 'orderby', $orderby );
						if( woo_ce_get_option( 'xml_attribute_order', 1 ) )
							$xml->addAttribute( 'order', $order );
						if( woo_ce_get_option( 'xml_attribute_limit', 1 ) )
							$xml->addAttribute( 'limit', $export->limit_volume );
						if( woo_ce_get_option( 'xml_attribute_offset', 1 ) )
							$xml->addAttribute( 'offset', $export->offset );
						$xml = woo_ce_export_dataset( $export->type, $xml );
					} else if( $export->export_format == 'rss' ) {
						$xml = new SED_SimpleXMLElement( sprintf( apply_filters( 'woo_ce_export_rss_first_line', '<?xml version="1.0" encoding="%s"?><rss version="2.0"%s/>' ), esc_attr( $export->encoding ), ' xmlns:g="http://base.google.com/ns/1.0"' ) );
						$child = $xml->addChild( apply_filters( 'woo_ce_export_rss_channel_node', 'channel' ) );
						$child->addChild( 'title', woo_ce_get_option( 'rss_title', '' ) );
						$child->addChild( 'link', woo_ce_get_option( 'rss_link', '' ) );
						$child->addChild( 'description', woo_ce_get_option( 'rss_description', '' ) );
						$bits = woo_ce_export_dataset( $export->type, $child );
					}
					$bits = woo_ce_format_xml( $xml );
				} else {
					$bits = false;
					error_log( '[store-exporter-deluxe] Error: The SimpleXMLElement class does not exist for XML file generation' );
				}
			}
			if( !empty( $bits ) ) {
				$output = '<p>' . __( 'Export completed successfully.', 'woo_ce' ) . '</p>';
				if( $gui == 'gui' )
					$output .= '<textarea readonly="readonly">' . esc_textarea( str_replace( '<br />', "\n", $bits ) ) . '</textarea>';
			} else {
				if( $gui == 'gui' ) {
					$output = sprintf( '<p>%s</p>', __( 'No export entries were found.', 'woo_ce' ) );
				} else {
					error_log( sprintf( '[store-exporter-deluxe] %s: Warning: %s', $export->filename, __( 'No export entries were found', 'woo_ce' ) ) );
					return false;
				}
			}
		}
	}

	// Return raw export to browser without file headers
	if( $gui == 'raw' && !empty( $bits ) ) {
		return $bits;
	// Return export as file download to browser
	} else if( $gui == 'download' && !empty( $bits ) ) {
		woo_ce_generate_file_headers( $post_mime_type );
		if( defined( 'DOING_AJAX' ) || get_transient( WOO_CD_PREFIX . '_single_export_format' ) !== false )
			echo $bits;
		else
			return $bits;
	// HTTP Post export contents to remote URL
	} else if( $gui == 'post' && !empty( $bits ) ) {
		$args = apply_filters( 'woo_ce_cron_export_post_args', array(
			'method'      => 'POST',
			'timeout'     => 60,
			'redirection' => 0,
			'httpversion' => '1.0',
			'sslverify'   => false,
			'blocking'    => true,
			'headers'     => array(
				'accept'       => $post_mime_type,
				'content-type' => $post_mime_type
			),
			'body'        => $bits,
			'cookies'     => array(),
			'user-agent'  => sprintf( 'WordPress/%s', $GLOBALS['wp_version'] ),
		) );
		$response = wp_remote_post( $export->to, $args );
		if( is_wp_error( $response ) ) {
			error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $response->get_error_message() ) );
			return false;
		} else {
			error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Remote POST sent to %s', 'woo_ce' ), $export->to ) ) );
		}
	// Output to screen in friendly design with on-screen error responses
	} else if( $gui == 'gui' ) {
		if( file_exists( WOO_CD_PATH . 'templates/admin/cron.php' ) ) {
			include_once( WOO_CD_PATH . 'templates/admin/cron.php' );
		} else {
			error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'Could not load template file within /templates/admin/cron.php', 'woo_ce' ) ) );
		}
		if( isset( $output ) )
			echo $output;
		echo '
	</body>
</html>';
	// Save export file to WordPress Media before sending/saving/etc. action
	} else if( in_array( $gui, array( 'gui', 'archive', 'url', 'file', 'email', 'ftp' ) ) ) {
		$upload = false;
		if( $export->filename && !empty( $bits ) ) {
			$post_ID = woo_ce_save_file_attachment( $export->filename, $post_mime_type );
			$upload = wp_upload_bits( $export->filename, null, $bits );
			if( ( $post_ID == false ) || $upload['error'] ) {
				wp_delete_attachment( $post_ID, true );
				error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $upload['error'] ) );
				return false;
			}
			if( file_exists( ABSPATH . 'wp-admin/includes/image.php' ) ) {
				include_once( ABSPATH . 'wp-admin/includes/image.php' );
				$attach_data = wp_generate_attachment_metadata( $post_ID, $upload['file'] );
				wp_update_attachment_metadata( $post_ID, $attach_data );
				update_attached_file( $post_ID, $upload['file'] );
				if( !empty( $post_ID ) ) {
					woo_ce_save_file_guid( $post_ID, $export->type, $upload['url'] );
					woo_ce_save_file_details( $post_ID );
				}
			} else {
				error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'Could not load image.php within /wp-admin/includes/image.php', 'woo_ce' ) ) );
			}
		}
		// Return URL to export file
		if( $gui == 'url' )
			return $upload['url'];
		// Return system path to export file
		if( $gui == 'file' )
			return $upload['file'];
		// E-mail export file to preferred address or WordPress site owner address
		if( $gui == 'email' ) {

			global $woocommerce;

			$mailer = $woocommerce->mailer();
			$subject = woo_ce_cron_email_subject( $export->type, $export->filename );
			$attachment = $upload['file'];
			$email_heading = sprintf( __( 'Export: %s', 'woo_ce' ), ucwords( $export->type ) );
			$recipient_name = apply_filters( 'woo_ce_email_recipient_name', __( 'there', 'woo_ce' ) );
			$email_contents = apply_filters( 'woo_ce_email_contents', wpautop( __( 'Please find attached your export ready to review.', 'woo_ce' ) ) );

			// Buffer
			ob_start();

			// Get mail template
			if( file_exists( WOO_CD_PATH . 'templates/emails/scheduled_export.php' ) ) {
				include_once( WOO_CD_PATH . 'templates/emails/scheduled_export.php' );
			} else {
				echo wpautop( sprintf( __( 'Hi %s', 'woo_ce' ), $recipient_name ) );
				echo $email_contents;
				error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, sprintf( __( 'Could not load template file %s within %s, defaulted to hard coded template.', 'woo_ce' ), 'scheduled_export.php', '/templates/emails/...' ) ) );
			}

			// Get contents
			$message = ob_get_clean();

			// Send the mail using WooCommerce mailer
			if( function_exists( 'woocommerce_mail' ) ) {
				woocommerce_mail( $export->to, $subject, $message, null, $attachment );
			} else {
				// Default to wp_mail()
				add_filter( 'wp_mail_content_type', 'woo_ce_set_html_content_type' );
				wp_mail( $export->to, $subject, $message, null, $attachment );
				remove_filter( 'wp_mail_content_type', 'woo_ce_set_html_content_type' );
			}
			// Delete the export file regardless of whether e-mail was successful or not
			wp_delete_attachment( $post_ID, true );
			error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Scheduled export e-mail of %s sent to %s', 'woo_ce' ), $export->filename, $export->to ) ) );

		}
		if( $gui == 'ftp' ) {

			// Load up our FTP/SFTP resources
			$host = woo_ce_get_option( 'auto_ftp_method_host', '' );
			if( !empty( $host ) )
				$host = woo_ce_format_ftp_host( $host );
			$port = woo_ce_get_option( 'auto_ftp_method_port', '' );
			$port = ( !empty( $port ) ? absint( $port ) : false );
			$user = woo_ce_get_option( 'auto_ftp_method_user', '' );
			$pass = woo_ce_get_option( 'auto_ftp_method_pass', '' );
			$path = woo_ce_get_option( 'auto_ftp_method_path', '' );
			$filename = woo_ce_get_option( 'auto_ftp_method_filename', '' );
			// Switch to fixed export filename if provided
			if( !empty( $filename ) )
				$export->filename = woo_ce_generate_filename( $export->type, $filename ) . '.' . $file_extension;

			// Check what protocol are we using; FTP or SFTP?
			$protocol = woo_ce_get_option( 'auto_ftp_method_protocol', 'ftp' );
			switch( $protocol ) {

				case 'ftp':
				default:
					// Check if ftp_connect() is available
					if( function_exists( 'ftp_connect' ) ) {
						$passive = woo_ce_get_option( 'auto_ftp_method_passive', '' );
						$timeout = woo_ce_get_option( 'auto_ftp_method_timeout', '' );
						if( $connection = @ftp_connect( $host, $port ) ) {
							// Update the FTP timeout if available and if a timeout was provided at export
							$remote_timeout = ftp_get_option( $connection, FTP_TIMEOUT_SEC );
							$timeout = absint( $timeout );
							if( $remote_timeout !== false && !empty( $timeout ) ) {
								// Compare the server timeout and the timeout provided at export
								if( $remote_timeout <> $timeout ) {
									if( ftp_set_option( $connection, FTP_TIMEOUT_SEC, $timeout ) == false )
										error_log( sprintf( '[store-exporter-deluxe] %s: Warning: %s', $export->filename, sprintf( __( 'Could not change the FTP server timeout on %s', 'woo_ce' ), $host ) ) );
								}
							}
							unset( $remote_timeout );
							if( ftp_login( $connection, $user, $pass ) ) {
								// Check if Transfer Mode is set to Auto/Pasive and if passive mode is available
								if( in_array( $passive, array( 'auto', 'passive' ) ) ) {
									$features = ftp_raw( $connection, 'FEAT' );
									if( !empty( $features ) ) {
										if( in_array( 'PASV', $features ) ) {
											if( ftp_pasv( $connection, true ) == false )
												error_log( sprintf( '[store-exporter-deluxe] %s: Warning: %s', 'woo_ce', $export->filename, sprintf( __( 'Could not switch to FTP passive mode on %s', 'woo_ce' ), $host ) ) );
										}
									}
								}
								// Change directory if neccesary
								if( !empty( $directory ) ) {
									$current_directory  = ftp_pwd( $connection );
									if( $current_directory !== false && @ftp_chdir( $connection, $path ) )
										ftp_chdir( $connection, $path );
								}
								if( ftp_put( $connection, sprintf( '%s/%s', $path, $export->filename ), $upload['file'], FTP_ASCII ) ) {
									error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Scheduled export of %s to %s via FTP uploaded', 'woo_ce' ), $export->filename, $path ) ) );
								} else {
									$export->error = sprintf( __( 'There was a problem uploading %s to %s via FTP, response: %s', 'woo_ce' ), $export->filename, $path, woo_ce_error_get_last_message() );
									error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
								}
							} else {
								$export->error = sprintf( __( 'Login incorrect for user %s on FTP server at %s, response: %s', 'woo_ce' ), $user, $host, woo_ce_error_get_last_message() );
								error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
							}
						} else {
							$export->error = sprintf( __( 'There was a problem connecting to %s via FTP', 'woo_ce' ), $host );
							error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
						}
					} else {
						$export->error = __( 'The function ftp_connect() is disabled within your WordPress site, cannot upload to FTP server', 'woo_ce' );
						error_log( __( '[store-exporter-deluxe] %s: Error: %s', 'woo_ce' ), $export->filename, $export->error );
					}
					break;

				case 'sftp':
					// Check if ssh2_connect() is available
					if( function_exists( 'ssh2_connect' ) ) {
						if( $connection = @ssh2_connect( $host, $port ) ) {
							if( ssh2_auth_password( $connection, $user, $pass ) ) {
								// Initialize SFTP subsystem
								if( $session = ssh2_sftp( $connection ) ) {
									if( $handle = fopen( sprintf( 'ssh2.sftp://%s/%s/%s', $session, $path, $export->filename ), 'w+' ) ) {
										error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Scheduled export of %s to %s via SFTP uploaded', 'woo_ce' ), $export->filename, $path ) ) );
									} else {
										$export->error = sprintf( __( 'There was a problem uploading %s to %s via SFTP', 'woo_ce' ), $export->filename, $path );
										error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
									}
								} else {
									$export->error = sprintf( __( 'Could not initialize SFTP subsystem on SFTP server at %s', 'woo_ce' ), $host );
									error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
								}
							} else {
								$export->error = sprintf( __( 'Login incorrect for user %s on SFTP server at %s', 'woo_ce' ), $user, $host );
								error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
							}
						} else {
							$export->error = sprintf( __( 'There was a problem connecting to %s via SFTP', 'woo_ce' ), $host );
							error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
						}
					} else {
						$export->error = __( 'The function ssh2_connect() is disabled within your WordPress site, cannot upload to SFTP server', 'woo_ce' );
						error_log( sprintf( __( '[store-exporter-deluxe] %s: Error: %s', 'woo_ce' ), $export->filename, $export->error ) );
					}
					break;

			}
			// Delete the export file regardless of whether upload was successful or not
			wp_delete_attachment( $post_ID, true );
		}
	}

	// Only include scheduled exports to the Recent Scheduled Exports list
	if( $export->scheduled_export ) {
		$recent_exports = woo_ce_get_option( 'recent_scheduled_exports', array() );
		if( empty( $recent_exports ) )
			$recent_exports = array();
		$size = count( $recent_exports );
		// Get the limit from the WordPress Dashboard widget
		if( !$widget_options = get_option( 'woo_ce_recent_scheduled_export_widget_options', array() ) ) {
			$widget_options = array(
				'number' => 5
			);
		}

		// Check if we have maxed out our recent scheduled exports
		if( $size >= $widget_options['number'] )
			array_shift( $recent_exports );
		$post_ID = ( isset( $post_ID ) ? $post_ID : 0 );
		$recent_exports[] = array(
			'post_id' => ( empty( $export->error ) ? $post_ID : 0 ),
			'name' => $export->filename,
			'date' => time(),
			'method' => $gui,
			'error' => $export->error
		);
		woo_ce_update_option( 'recent_scheduled_exports', $recent_exports );
	}

	delete_option( WOO_CD_PREFIX . '_exported' );

	// If the CRON process gets this far, pass on the good news!
	return true;

}
コード例 #5
0
ファイル: exporter.php プロジェクト: hikaram/wee
 function woo_ce_admin_init()
 {
     global $export, $wp_roles;
     // Now is the time to de-activate Store Exporter if Store Exporter Deluxe is activated
     if (defined('WOO_CD_PREFIX')) {
         include_once WOO_CE_PATH . 'includes/install.php';
         woo_ce_deactivate_ce();
         return;
     }
     // Detect if WooCommerce Subscriptions Exporter is activated
     if (function_exists('wc_subs_exporter_admin_init')) {
         $message = sprintf(__('We have detected a WooCommerce Plugin that is activated and known to conflict with Store Exporter, please de-activate WooCommerce Subscriptions Exporter to resolve export issues. <a href="%s" target="_blank">Need help?</a>', 'woocommerce-exporter'), $troubleshooting_url);
         woo_cd_admin_notice($message, 'error', array('plugins.php', 'admin.php'));
     }
     // Check that we are on the Store Exporter screen
     $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : false;
     if ($page != strtolower(WOO_CE_PREFIX)) {
         return;
     }
     // Detect other platform versions
     woo_ce_detect_non_woo_install();
     // Process any pre-export notice confirmations
     $action = woo_get_action();
     switch ($action) {
         // Prompt on Export screen when insufficient memory (less than 64M is allocated)
         case 'dismiss_memory_prompt':
             woo_ce_update_option('dismiss_memory_prompt', 1);
             $url = esc_url(add_query_arg('action', null));
             wp_redirect($url);
             exit;
             break;
             // Prompt on Export screen when PHP configuration option max_execution_time cannot be increased
         // Prompt on Export screen when PHP configuration option max_execution_time cannot be increased
         case 'dismiss_execution_time_prompt':
             woo_ce_update_option('dismiss_execution_time_prompt', 1);
             $url = esc_url(add_query_arg('action', null));
             wp_redirect($url);
             exit;
             break;
             // Prompt on Export screen when insufficient memory (less than 64M is allocated)
         // Prompt on Export screen when insufficient memory (less than 64M is allocated)
         case 'dismiss_php_legacy':
             woo_ce_update_option('dismiss_php_legacy', 1);
             $url = esc_url(add_query_arg('action', null));
             wp_redirect($url);
             exit;
             break;
         case 'dismiss_subscription_prompt':
             woo_ce_update_option('dismiss_subscription_prompt', 1);
             $url = esc_url(add_query_arg('action', null));
             wp_redirect($url);
             exit;
             break;
             // Save skip overview preference
         // Save skip overview preference
         case 'skip_overview':
             $skip_overview = false;
             if (isset($_POST['skip_overview'])) {
                 $skip_overview = 1;
             }
             woo_ce_update_option('skip_overview', $skip_overview);
             if ($skip_overview == 1) {
                 $url = esc_url(add_query_arg('tab', 'export'));
                 wp_redirect($url);
                 exit;
             }
             break;
             // This is where the magic happens
         // This is where the magic happens
         case 'export':
             // Make sure we play nice with other WooCommerce and WordPress exporters
             if (isset($_POST['woo_ce_export']) && !check_admin_referer('manual_export', 'woo_ce_export')) {
                 return false;
             }
             // Set up the basic export options
             $export = new stdClass();
             $export->cron = 0;
             $export->scheduled_export = 0;
             $export->start_time = time();
             $export->idle_memory_start = woo_ce_current_memory_usage();
             $export->delete_file = woo_ce_get_option('delete_file', 0);
             $export->encoding = woo_ce_get_option('encoding', get_option('blog_charset', 'UTF-8'));
             // Reset the Encoding if corrupted
             if ($export->encoding == '' || $export->encoding == false || $export->encoding == 'System default') {
                 error_log('[store-exporter] Encoding export option was corrupted, defaulted to UTF-8');
                 $export->encoding = 'UTF-8';
                 woo_ce_update_option('encoding', 'UTF-8');
             }
             $export->delimiter = woo_ce_get_option('delimiter', ',');
             // Reset the Delimiter if corrupted
             if ($export->delimiter == '' || $export->delimiter == false) {
                 error_log('[store-exporter] Delimiter export option was corrupted, defaulted to ,');
                 $export->delimiter = ',';
                 woo_ce_update_option('delimiter', ',');
             }
             $export->category_separator = woo_ce_get_option('category_separator', '|');
             // Reset the Category Separator if corrupted
             if ($export->category_separator == '' || $export->category_separator == false) {
                 error_log('[store-exporter] Category Separator export option was corrupted, defaulted to |');
                 $export->category_separator = '|';
                 woo_ce_update_option('category_separator', '|');
             }
             $export->bom = woo_ce_get_option('bom', 1);
             $export->escape_formatting = woo_ce_get_option('escape_formatting', 'all');
             // Reset the Escape Formatting if corrupted
             if ($export->escape_formatting == '' || $export->escape_formatting == false) {
                 error_log('[store-exporter] Escape Formatting export option was corrupted, defaulted to all');
                 $export->escape_formatting = 'all';
                 woo_ce_update_option('escape_formatting', 'all');
             }
             $export->date_format = woo_ce_get_option('date_format', 'd/m/Y');
             // Reset the Date Format if corrupted
             if ($export->date_format == '1' || $export->date_format == '' || $export->date_format == false) {
                 error_log('[store-exporter] Date Format export option was corrupted, defaulted to d/m/Y');
                 $export->date_format = 'd/m/Y';
                 woo_ce_update_option('date_format', 'd/m/Y');
             }
             // Save export option changes made on the Export screen
             $export->limit_volume = isset($_POST['limit_volume']) ? sanitize_text_field($_POST['limit_volume']) : '';
             woo_ce_update_option('limit_volume', $export->limit_volume);
             if ($export->limit_volume == '') {
                 $export->limit_volume = -1;
             }
             $export->offset = isset($_POST['offset']) ? sanitize_text_field($_POST['offset']) : '';
             woo_ce_update_option('offset', $export->offset);
             if ($export->offset == '') {
                 $export->offset = 0;
             }
             // Set default values for all export options to be later passed onto the export process
             $export->fields = array();
             $export->fields_order = false;
             $export->export_format = 'csv';
             // Product sorting
             $export->product_categories = false;
             $export->product_tags = false;
             $export->product_status = false;
             $export->product_type = false;
             $export->product_orderby = false;
             $export->product_order = false;
             $export->gallery_formatting = false;
             $export->upsell_formatting = false;
             $export->crosssell_formatting = false;
             // Category sorting
             $export->category_orderby = false;
             $export->category_order = false;
             // Tag sorting
             $export->tag_orderby = false;
             $export->tag_order = false;
             // User sorting
             $export->user_orderby = false;
             $export->user_order = false;
             $export->type = isset($_POST['dataset']) ? sanitize_text_field($_POST['dataset']) : false;
             if ($export->type) {
                 $export->fields = isset($_POST[$export->type . '_fields']) ? array_map('sanitize_text_field', $_POST[$export->type . '_fields']) : false;
                 $export->fields_order = isset($_POST[$export->type . '_fields_order']) ? array_map('absint', $_POST[$export->type . '_fields_order']) : false;
                 woo_ce_update_option('last_export', $export->type);
             }
             switch ($export->type) {
                 case 'product':
                     // Set up dataset specific options
                     $export->product_categories = isset($_POST['product_filter_category']) ? woo_ce_format_product_filters(array_map('absint', $_POST['product_filter_category'])) : false;
                     $export->product_tags = isset($_POST['product_filter_tag']) ? woo_ce_format_product_filters(array_map('absint', $_POST['product_filter_tag'])) : false;
                     $export->product_status = isset($_POST['product_filter_status']) ? woo_ce_format_product_filters(array_map('sanitize_text_field', $_POST['product_filter_status'])) : false;
                     $export->product_type = isset($_POST['product_filter_type']) ? woo_ce_format_product_filters(array_map('sanitize_text_field', $_POST['product_filter_type'])) : false;
                     $export->product_orderby = isset($_POST['product_orderby']) ? sanitize_text_field($_POST['product_orderby']) : false;
                     $export->product_order = isset($_POST['product_order']) ? sanitize_text_field($_POST['product_order']) : false;
                     $export->gallery_formatting = isset($_POST['product_gallery_formatting']) ? absint($_POST['product_gallery_formatting']) : false;
                     $export->upsell_formatting = isset($_POST['product_upsell_formatting']) ? absint($_POST['product_upsell_formatting']) : false;
                     $export->crosssell_formatting = isset($_POST['product_crosssell_formatting']) ? absint($_POST['product_crosssell_formatting']) : false;
                     // Save dataset export specific options
                     if ($export->product_orderby != woo_ce_get_option('product_orderby')) {
                         woo_ce_update_option('product_orderby', $export->product_orderby);
                     }
                     if ($export->product_order != woo_ce_get_option('product_order')) {
                         woo_ce_update_option('product_order', $export->product_order);
                     }
                     if ($export->upsell_formatting != woo_ce_get_option('upsell_formatting')) {
                         woo_ce_update_option('upsell_formatting', $export->upsell_formatting);
                     }
                     if ($export->crosssell_formatting != woo_ce_get_option('crosssell_formatting')) {
                         woo_ce_update_option('crosssell_formatting', $export->crosssell_formatting);
                     }
                     break;
                 case 'category':
                     // Set up dataset specific options
                     $export->category_orderby = isset($_POST['category_orderby']) ? sanitize_text_field($_POST['category_orderby']) : false;
                     $export->category_order = isset($_POST['category_order']) ? sanitize_text_field($_POST['category_order']) : false;
                     // Save dataset export specific options
                     if ($export->category_orderby != woo_ce_get_option('category_orderby')) {
                         woo_ce_update_option('category_orderby', $export->category_orderby);
                     }
                     if ($export->category_order != woo_ce_get_option('category_order')) {
                         woo_ce_update_option('category_order', $export->category_order);
                     }
                     break;
                 case 'tag':
                     // Set up dataset specific options
                     $export->tag_orderby = isset($_POST['tag_orderby']) ? sanitize_text_field($_POST['tag_orderby']) : false;
                     $export->tag_order = isset($_POST['tag_order']) ? sanitize_text_field($_POST['tag_order']) : false;
                     // Save dataset export specific options
                     if ($export->tag_orderby != woo_ce_get_option('tag_orderby')) {
                         woo_ce_update_option('tag_orderby', $export->tag_orderby);
                     }
                     if ($export->tag_order != woo_ce_get_option('tag_order')) {
                         woo_ce_update_option('tag_order', $export->tag_order);
                     }
                     break;
                 case 'user':
                     // Set up dataset specific options
                     $export->user_orderby = isset($_POST['user_orderby']) ? sanitize_text_field($_POST['user_orderby']) : false;
                     $export->user_order = isset($_POST['user_order']) ? sanitize_text_field($_POST['user_order']) : false;
                     // Save dataset export specific options
                     if ($export->user_orderby != woo_ce_get_option('user_orderby')) {
                         woo_ce_update_option('user_orderby', $export->user_orderby);
                     }
                     if ($export->user_order != woo_ce_get_option('user_order')) {
                         woo_ce_update_option('user_order', $export->user_order);
                     }
                     break;
             }
             if ($export->type) {
                 $timeout = 600;
                 if (isset($_POST['timeout'])) {
                     $timeout = absint((int) $_POST['timeout']);
                     if ($timeout != woo_ce_get_option('timeout')) {
                         woo_ce_update_option('timeout', $timeout);
                     }
                 }
                 if (!ini_get('safe_mode')) {
                     @set_time_limit((int) $timeout);
                 }
                 @ini_set('memory_limit', WP_MAX_MEMORY_LIMIT);
                 @ini_set('max_execution_time', (int) $timeout);
                 $export->args = array('limit_volume' => $export->limit_volume, 'offset' => $export->offset, 'encoding' => $export->encoding, 'date_format' => $export->date_format, 'product_categories' => $export->product_categories, 'product_tags' => $export->product_tags, 'product_status' => $export->product_status, 'product_type' => $export->product_type, 'product_orderby' => $export->product_orderby, 'product_order' => $export->product_order, 'category_orderby' => $export->category_orderby, 'category_order' => $export->category_order, 'tag_orderby' => $export->tag_orderby, 'tag_order' => $export->tag_order, 'user_orderby' => $export->user_orderby, 'user_order' => $export->user_order);
                 if (empty($export->fields)) {
                     $message = __('No export fields were selected, please try again with at least a single export field.', 'woocommerce-exporter');
                     woo_ce_admin_notice($message, 'error');
                     return false;
                 }
                 woo_ce_save_fields($export->type, $export->fields, $export->fields_order);
                 if ($export->export_format == 'csv') {
                     $export->filename = woo_ce_generate_csv_filename($export->type);
                 }
                 // Print file contents to debug export screen
                 if (WOO_CE_DEBUG) {
                     if (in_array($export->export_format, array('csv'))) {
                         woo_ce_export_dataset($export->type);
                     }
                     $export->idle_memory_end = woo_ce_current_memory_usage();
                     $export->end_time = time();
                     // Print file contents to browser
                 } else {
                     if (in_array($export->export_format, array('csv'))) {
                         // Generate CSV contents
                         $bits = woo_ce_export_dataset($export->type);
                         unset($export->fields);
                         if (!$bits) {
                             $message = __('No export entries were found, please try again with different export filters.', 'woocommerce-exporter');
                             woo_ce_admin_notice($message, 'error');
                             return false;
                         }
                         if ($export->delete_file) {
                             // Print to browser
                             if ($export->export_format == 'csv') {
                                 woo_ce_generate_csv_header($export->type);
                             }
                             echo $bits;
                             exit;
                         } else {
                             // Save to file and insert to WordPress Media
                             if ($export->filename && $bits) {
                                 if ($export->export_format == 'csv') {
                                     $post_ID = woo_ce_save_file_attachment($export->filename, 'text/csv');
                                 }
                                 $upload = wp_upload_bits($export->filename, null, $bits);
                                 if ($post_ID == false || $upload['error']) {
                                     wp_delete_attachment($post_ID, true);
                                     if (isset($upload['error'])) {
                                         wp_redirect(esc_url(add_query_arg(array('failed' => true, 'message' => urlencode($upload['error'])))));
                                     } else {
                                         wp_redirect(esc_url(add_query_arg(array('failed' => true))));
                                     }
                                     return false;
                                 }
                                 $attach_data = wp_generate_attachment_metadata($post_ID, $upload['file']);
                                 wp_update_attachment_metadata($post_ID, $attach_data);
                                 update_attached_file($post_ID, $upload['file']);
                                 if ($post_ID) {
                                     woo_ce_save_file_guid($post_ID, $export->type, $upload['url']);
                                     woo_ce_save_file_details($post_ID);
                                 }
                                 $export_type = $export->type;
                                 unset($export);
                                 // The end memory usage and time is collected at the very last opportunity prior to the CSV header being rendered to the screen
                                 woo_ce_update_file_detail($post_ID, '_woo_idle_memory_end', woo_ce_current_memory_usage());
                                 woo_ce_update_file_detail($post_ID, '_woo_end_time', time());
                                 // Generate CSV header
                                 woo_ce_generate_csv_header($export_type);
                                 unset($export_type);
                                 // Print file contents to screen
                                 if ($upload['file']) {
                                     readfile($upload['file']);
                                 } else {
                                     wp_redirect(esc_url(add_query_arg('failed', true)));
                                 }
                                 unset($upload);
                             } else {
                                 wp_redirect(esc_url(add_query_arg('failed', true)));
                             }
                         }
                     }
                     exit;
                 }
             }
             break;
             // Save changes on Settings screen
         // Save changes on Settings screen
         case 'save-settings':
             // Sanitize each setting field as needed
             woo_ce_update_option('export_filename', strip_tags((string) $_POST['export_filename']));
             woo_ce_update_option('delete_file', sanitize_text_field((int) $_POST['delete_file']));
             woo_ce_update_option('encoding', sanitize_text_field((string) $_POST['encoding']));
             woo_ce_update_option('delimiter', sanitize_text_field((string) $_POST['delimiter']));
             woo_ce_update_option('category_separator', sanitize_text_field((string) $_POST['category_separator']));
             woo_ce_update_option('bom', absint((int) $_POST['bom']));
             woo_ce_update_option('escape_formatting', sanitize_text_field((string) $_POST['escape_formatting']));
             if ($_POST['date_format'] == 'custom' && !empty($_POST['date_format_custom'])) {
                 woo_ce_update_option('date_format', sanitize_text_field((string) $_POST['date_format_custom']));
             } else {
                 woo_ce_update_option('date_format', sanitize_text_field((string) $_POST['date_format']));
             }
             $message = __('Changes have been saved.', 'woocommerce-exporter');
             woo_ce_admin_notice($message);
             break;
             // Save changes on Field Editor screen
         // Save changes on Field Editor screen
         case 'save-fields':
             $fields = isset($_POST['fields']) ? array_filter($_POST['fields']) : array();
             $types = array_keys(woo_ce_return_export_types());
             $export_type = isset($_POST['type']) ? sanitize_text_field($_POST['type']) : '';
             if (in_array($export_type, $types)) {
                 woo_ce_update_option($export_type . '_labels', $fields);
                 $message = __('Changes have been saved.', 'woocommerce-exporter');
                 woo_ce_admin_notice($message);
             } else {
                 $message = __('Changes could not be saved.', 'woocommerce-exporter');
                 woo_ce_admin_notice($message, 'error');
             }
             break;
     }
 }
コード例 #6
0
function woo_ce_export_settings_extend() {

	// XML settings
	$xml_attribute_url = woo_ce_get_option( 'xml_attribute_url', 1 );
	$xml_attribute_title = woo_ce_get_option( 'xml_attribute_title', 1 );
	$xml_attribute_date = woo_ce_get_option( 'xml_attribute_date', 1 );
	$xml_attribute_time = woo_ce_get_option( 'xml_attribute_time', 0 );
	$xml_attribute_export = woo_ce_get_option( 'xml_attribute_export', 1 );
	$xml_attribute_orderby = woo_ce_get_option( 'xml_attribute_orderby', 0 );
	$xml_attribute_order = woo_ce_get_option( 'xml_attribute_order', 0 );
	$xml_attribute_limit = woo_ce_get_option( 'xml_attribute_limit', 0 );
	$xml_attribute_offset = woo_ce_get_option( 'xml_attribute_offset', 0 );

	// RSS settings
	$rss_title = woo_ce_get_option( 'rss_title', '' );
	$rss_link = woo_ce_get_option( 'rss_link', '' );
	$rss_description = woo_ce_get_option( 'rss_description', '' );

	// Scheduled exports
	$enable_auto = woo_ce_get_option( 'enable_auto', 0 );
	$auto_schedule = woo_ce_get_option( 'auto_schedule', 'custom' );
	$auto_interval = woo_ce_get_option( 'auto_interval', 1440 );
	$auto_commence = woo_ce_get_option( 'auto_commence', 'now' );
	$auto_commence_date = woo_ce_get_option( 'auto_commence_date', date( 'd/m/Y H:i', current_time( 'timestamp', 1 ) ) );
	// Legacy update of Comment Date to support time
	if( strlen( $auto_commence_date ) <= 10 ) {
		$auto_commence_date .= sprintf( ' %s', date( 'H:i', current_time( 'timestamp', 1 ) ) );
	}
	if( $enable_auto == 1 ) {
		if( ( $next_export = woo_ce_next_scheduled_export() ) == false )
			$next_export = __( 'a little while... just waiting on WP-CRON to refresh its task list', 'woo_ce' );
		if( $auto_schedule <> 'custom' )
			$next_export = sprintf( __( '%s (in %s)', 'woo_ce' ), $auto_schedule, $next_export );
	}
	$auto_type = woo_ce_get_option( 'auto_type', 'product' );
	$types = woo_ce_return_export_types();
	$order_statuses = woo_ce_get_order_statuses();
	$product_types = woo_ce_get_product_types();
	$args = array(
		'hide_empty' => 1
	);
	$product_categories = woo_ce_get_product_categories( $args );
	$product_tags = woo_ce_get_product_tags( $args );
	$product_statuses = get_post_statuses();
	if( !isset( $product_statuses['trash'] ) )
		$product_statuses['trash'] = __( 'Trash', 'woo_ce' );

	$product_filter_type = woo_ce_get_option( 'auto_product_type', array() );
	$product_filter_status = woo_ce_get_option( 'auto_product_status', array() );
	$product_filter_stock = woo_ce_get_option( 'auto_product_stock', false );
	$product_filter_category = woo_ce_get_option( 'auto_product_category', array() );
	$product_filter_tag = woo_ce_get_option( 'auto_product_tag', array() );

	$order_filter_status = woo_ce_get_option( 'auto_order_status', array() );
	if( empty( $order_filter_status ) )
		$order_filter_status = array();
	$order_filter_product = woo_ce_get_option( 'auto_order_product', array() );
	if( empty( $order_filter_product ) )
		$order_filter_product = array();
	$order_filter_date = woo_ce_get_option( 'auto_order_date', false );
	$order_filter_dates_from = woo_ce_get_option( 'auto_order_dates_from', '' );
	$order_filter_dates_to = woo_ce_get_option( 'auto_order_dates_to', '' );
	$order_filter_date_variable = woo_ce_get_option( 'auto_order_date_variable', '' );
	$order_filter_date_variable_length = woo_ce_get_option( 'auto_order_date_variable_length', '' );
	$countries = woo_ce_allowed_countries();
	$order_filter_billing_country = woo_ce_get_option( 'auto_order_billing_country', array() );
	$order_filter_shipping_country = woo_ce_get_option( 'auto_order_shipping_country', array() );
	$payment_gateways = woo_ce_get_order_payment_gateways();
	$order_filter_payment = woo_ce_get_option( 'auto_order_payment', array() );
	$shipping_methods = woo_ce_get_order_shipping_methods();
	$order_filter_shipping = woo_ce_get_option( 'auto_order_shipping', array() );

	$auto_format = woo_ce_get_option( 'auto_format', 'csv' );
	$auto_method = woo_ce_get_option( 'auto_method', 'archive' );

	// Send to e-mail
	$email_to = woo_ce_get_option( 'email_to', get_option( 'admin_email', '' ) );
	$email_subject = woo_ce_get_option( 'email_subject', '' );
	// Default subject
	if( empty( $email_subject ) )
		$email_subject = __( '[%store_name%] Export: %export_type% (%export_filename%)', 'woo_ce' );

	// Post to remote URL
	$post_to = woo_ce_get_option( 'post_to', '' );

	// Export to FTP
	$ftp_method_host = woo_ce_get_option( 'auto_ftp_method_host', '' );
	$ftp_method_port = woo_ce_get_option( 'auto_ftp_method_port', '' );
	$ftp_method_protocol = woo_ce_get_option( 'auto_ftp_method_protocol', 'ftp' );
	$ftp_method_user = woo_ce_get_option( 'auto_ftp_method_user', '' );
	$ftp_method_pass = woo_ce_get_option( 'auto_ftp_method_pass', '' );
	$ftp_method_path = woo_ce_get_option( 'auto_ftp_method_path', '' );
	$ftp_method_filename = woo_ce_get_option( 'auto_ftp_method_filename', '' );
	$ftp_method_passive = woo_ce_get_option( 'auto_ftp_method_passive', '' );
	$ftp_method_timeout = woo_ce_get_option( 'auto_ftp_method_timeout', '' );

	$scheduled_fields = woo_ce_get_option( 'scheduled_fields', 'all' );

	// CRON exports
	$enable_cron = woo_ce_get_option( 'enable_cron', 0 );
	$secret_key = woo_ce_get_option( 'secret_key', '' );

	$cron_fields = woo_ce_get_option( 'cron_fields', 'all' );

	// Orders Screen
	$order_actions_csv = woo_ce_get_option( 'order_actions_csv', 1 );
	$order_actions_xml = woo_ce_get_option( 'order_actions_xml', 0 );
	$order_actions_xls = woo_ce_get_option( 'order_actions_xls', 1 );
	$order_actions_xlsx = woo_ce_get_option( 'order_actions_xlsx', 1 );

	// Export Triggers
	$enable_trigger_new_order = woo_ce_get_option( 'enable_trigger_new_order', 0 );
	$trigger_new_order_format = woo_ce_get_option( 'trigger_new_order_format', 'csv' );
	$trigger_new_order_method = woo_ce_get_option( 'trigger_new_order_format', 'archive' );
	$trigger_new_order_fields = woo_ce_get_option( 'trigger_new_order_fields', 'all' );

	$troubleshooting_url = 'http://www.visser.com.au/documentation/store-exporter-deluxe/usage/';

	ob_start(); ?>
<tr id="xml-settings">
	<td colspan="2" style="padding:0;">
		<hr />
		<h3><div class="dashicons dashicons-media-code"></div>&nbsp;<?php _e( 'XML Settings', 'woo_ce' ); ?></h3>
	</td>
</tr>
<tr>
	<th>
		<label><?php _e( 'Attribute display', 'woo_ce' ); ?></label>
	</th>
	<td>
		<ul>
			<li><label><input type="checkbox" name="xml_attribute_url" value="1"<?php checked( $xml_attribute_url ); ?> /> <?php _e( 'Site Address', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="xml_attribute_title" value="1"<?php checked( $xml_attribute_title ); ?> /> <?php _e( 'Site Title', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="xml_attribute_date" value="1"<?php checked( $xml_attribute_date ); ?> /> <?php _e( 'Export Date', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="xml_attribute_time" value="1"<?php checked( $xml_attribute_time ); ?> /> <?php _e( 'Export Time', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="xml_attribute_export" value="1"<?php checked( $xml_attribute_export ); ?> /> <?php _e( 'Export Type', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="xml_attribute_orderby" value="1"<?php checked( $xml_attribute_orderby ); ?> /> <?php _e( 'Export Order By', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="xml_attribute_order" value="1"<?php checked( $xml_attribute_order ); ?> /> <?php _e( 'Export Order', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="xml_attribute_limit" value="1"<?php checked( $xml_attribute_limit ); ?> /> <?php _e( 'Limit Volume', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="xml_attribute_offset" value="1"<?php checked( $xml_attribute_offset ); ?> /> <?php _e( 'Volume Offset', 'woo_ce' ); ?></label></li>
		</ul>
		<p class="description"><?php _e( 'Control the visibility of different attributes in the XML export.', 'woo_ce' ); ?></p>
	</td>
</tr>

<tr id="rss-settings">
	<td colspan="2" style="padding:0;">
		<hr />
		<h3><div class="dashicons dashicons-media-code"></div>&nbsp;<?php _e( 'RSS Settings', 'woo_ce' ); ?></h3>
	</td>
</tr>
<tr>
	<th>
		<label for="rss_title"><?php _e( 'Title element', 'woo_ce' ); ?></label>
	</th>
	<td>
		<input name="rss_title" type="text" id="rss_title" value="<?php echo esc_attr( $rss_title ); ?>" class="large-text" />
		<p class="description"><?php _e( 'Defines the title of the data feed (e.g. Product export for WordPress Shop).', 'woo_ce' ); ?></p>
	</td>
</tr>
<tr>
	<th>
		<label for="rss_link"><?php _e( 'Link element', 'woo_ce' ); ?></label>
	</th>
	<td>
		<input name="rss_link" type="text" id="rss_link" value="<?php echo esc_attr( $rss_link ); ?>" class="large-text" />
		<p class="description"><?php _e( 'A link to your website, this doesn\'t have to be the location of the RSS feed.', 'woo_ce' ); ?></p>
	</td>
</tr>
<tr>
	<th>
		<label for="rss_description"><?php _e( 'Description element', 'woo_ce' ); ?></label>
	</th>
	<td>
		<input name="rss_description" type="text" id="rss_description" value="<?php echo esc_attr( $rss_description ); ?>" class="large-text" />
		<p class="description"><?php _e( 'A description of your data feed.', 'woo_ce' ); ?></p>
	</td>
</tr>

<tr id="scheduled-exports">
	<td colspan="2" style="padding:0;">
		<hr />
		<h3>
			<div class="dashicons dashicons-calendar"></div>&nbsp;<?php _e( 'Scheduled Exports', 'woo_ce' ); ?>
			<!-- <a href="/woocommerce/wp-admin/admin.php?page=woo_ce&amp;tab=export" class="add-new-h2">Add New</a> -->
		</h3>
<?php if( $enable_auto == 1 ) { ?>
		<p style="font-size:0.8em;"><div class="dashicons dashicons-yes"></div>&nbsp;<strong><?php printf( __( 'Scheduled Exports is enabled, next scheduled export will run %s.', 'woo_ce' ), $next_export ); ?></strong></p>
<?php } ?>
		<p class="description"><?php _e( 'Configure Store Exporter Deluxe to automatically generate exports, apply filters to export just what you need.<br />Adjusting options within the Scheduling sub-section will after clicking Save Changes refresh the scheduled export engine, editing filters, formats, methods, etc. will not affect the scheduling of the current scheduled export.', 'woo_ce' ); ?></p>
	</td>
</tr>
<tr>
	<th>
		<label for="enable_auto"><?php _e( 'Enable scheduled exports', 'woo_ce' ); ?></label>
	</th>
	<td>
		<select id="enable_auto" name="enable_auto">
			<option value="1"<?php selected( $enable_auto, 1 ); ?>><?php _e( 'Yes', 'woo_ce' ); ?></option>
			<option value="0"<?php selected( $enable_auto, 0 ); ?>><?php _e( 'No', 'woo_ce' ); ?></option>
		</select>
		<p class="description"><?php _e( 'Enabling Scheduled Exports will trigger automated exports at the interval specified under Scheduling.', 'woo_ce' ); ?></p>
	</td>
</tr>
<!--
<tr>
	<th>&nbsp;</th>
	<td style="padding:1em 0 1em 0.8em;">

		<table class="widefat page fixed scheduled-exports">
			<thead>
				<tr>
					<th scope="col" id="cb" class="manage-column column-cb check-column">
						<label class="screen-reader-text" for="cb-select-all-1"><?php _e( 'Select All', 'woo_ce' ); ?></label><input id="cb-select-all-1" type="checkbox" />
					</th>
					<th class="manage-column"><?php _e( 'Name', 'woo_ce' ); ?></th>
					<th class="manage-column"><?php _e( 'Type', 'woo_ce' ); ?></th>
					<th class="manage-column"><?php _e( 'Format', 'woo_ce' ); ?></th>
					<th class="manage-column"><?php _e( 'Status', 'woo_ce' ); ?></th>
					<th class="manage-column"><?php _e( 'Date', 'woo_ce' ); ?></th>
					<th class="manage-column separator">&nbsp;</th>
				</tr>
			</thead>
			<tbody>

<?php if( !empty( $posts ) ) { ?>
				<tr>
					<th scope="row" class="check-column">
						<label class="screen-reader-text" for="cb-select-18619"><?php printf( __( 'Select %s', 'woo_ce' ), get_the_title( $post ) ); ?></label>
						<input id="cb-select-<?php echo $post; ?>" type="checkbox" name="post[]" value="<?php echo $post; ?>">
					</th>
					<td>My Daily Product Export</td>
					<td>Product</td>
					<td>CSV</td>
					<td>Enabled</td>
					<td>30 days ago</td>
					<td class="edit"><a href="#">Edit</a></td>
				</tr>
<?php } else { ?>
				<tr>
						<td class="colspanchange" colspan="6"><?php _e( 'No scheduled exports found.', 'woo_ce' ); ?></td>
				</tr>
<?php } ?>

			</tbody>
		</table>

	</td>
</tr>
-->
<tr>
	<th>
		<label for="auto_type"><?php _e( 'Export type', 'woo_ce' ); ?></label>
	</th>
	<td>
		<select id="auto_type" name="auto_type">
<?php if( !empty( $types ) ) { ?>
	<?php foreach( $types as $key => $type ) { ?>
			<option value="<?php echo $key; ?>"<?php selected( $auto_type, $key ); ?>><?php echo $type; ?></option>
	<?php } ?>
<?php } else { ?>
			<option value=""><?php _e( 'No export types were found.', 'woo_ce' ); ?></option>
<?php } ?>
		</select>
		<p class="description"><?php _e( 'Select the data type you want to export.', 'woo_ce' ); ?></p>
	</td>
</tr>
<tr class="auto_type_options">
	<th>
		<label><?php _e( 'Export filters', 'woo_ce' ); ?></label>
	</th>
	<td>
		<ul>

			<li class="export-options product-options">
				<p class="label"><?php _e( 'Product category', 'woo_ce' ); ?></p>
<?php if( !empty( $product_categories ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Product Category...', 'woo_ce' ); ?>" name="product_filter_category[]" multiple class="chzn-select" style="width:95%;">
	<?php foreach( $product_categories as $product_category ) { ?>
					<option value="<?php echo $product_category->term_id; ?>"<?php checked( in_array( $product_category->term_id, $product_filter_category ), true ); ?><?php disabled( $product_category->count, 0 ); ?>><?php echo woo_ce_format_product_category_label( $product_category->name, $product_category->parent_name ); ?> (<?php printf( __( 'Term ID: %d', 'woo_ce' ), $product_category->term_id ); ?>)</option>
	<?php } ?>
				</select>
<?php } else { ?>
				<?php _e( 'No Product Categories were found.', 'woo_ce' ); ?>
<?php } ?>
				<p class="description"><?php _e( 'Select the Product Category\'s you want to filter exported Products by. Default is to include all Product Categories.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options product-options">
				<p class="label"><?php _e( 'Product tag', 'woo_ce' ); ?></p>
<?php if( !empty( $product_tags ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Product Tag...', 'woo_ce' ); ?>" name="product_filter_tag[]" multiple class="chzn-select" style="width:95%;">
	<?php foreach( $product_tags as $product_tag ) { ?>
					<option value="<?php echo $product_tag->term_id; ?>"<?php selected( in_array( $product_tag->term_id, $product_filter_tag ), true ); ?><?php disabled( $product_category->count, 0 ); ?>><?php echo $product_tag->name; ?> (<?php printf( __( 'Term ID: %d', 'woo_ce' ), $product_tag->term_id ); ?>)</option>
	<?php } ?>
				</select>
<?php } else { ?>
				<?php _e( 'No Product Tags were found.', 'woo_ce' ); ?>
<?php } ?>
				<p class="description"><?php _e( 'Select the Product Tag\'s you want to filter exported Products by. Default is to include all Product Tags.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options product-options">
				<p class="label"><?php _e( 'Product status', 'woo_ce' ); ?></p>
<?php if( !empty( $product_statuses ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Product Status...', 'woo_ce' ); ?>" name="product_filter_status[]" multiple class="chzn-select" style="width:95%;">
	<?php foreach( $product_statuses as $key => $product_status ) { ?>
					<option value="<?php echo $key; ?>"<?php selected( in_array( $key, $product_filter_status ), true ); ?>><?php echo $product_status; ?></option>
	<?php } ?>
				</select>
<?php } else { ?>
				<?php _e( 'No Product Status were found.', 'woo_ce' ); ?>
<?php } ?>
				<p class="description"><?php _e( 'Select the Product Status\'s you want to filter exported Products by. Default is to include all Product Status\'s.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options product-options">
				<p class="label"><?php _e( 'Product type', 'woo_ce' ); ?></p>
<?php if( !empty( $product_types ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Product Type...', 'woo_ce' ); ?>" name="product_filter_type[]" multiple class="chzn-select" style="width:95%;">
	<?php foreach( $product_types as $key => $product_type ) { ?>
					<option value="<?php echo $key; ?>"<?php selected( in_array( $key, $product_filter_type ), true ); ?>><?php echo woo_ce_format_product_type( $product_type['name'] ); ?> (<?php echo $product_type['count']; ?>)</option>
	<?php } ?>
				</select>
<?php } else { ?>
				<?php _e( 'No Product Types were found.', 'woo_ce' ); ?>
<?php } ?>
				<p class="description"><?php _e( 'Select the Product Type\'s you want to filter exported Products by. Default is to include all Product Types except Variations.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options product-options">
				<p class="label"><?php _e( 'Stock status', 'woo_ce' ); ?></p>
				<ul style="margin-top:0.2em;">
					<li><label><input type="radio" name="product_filter_stock" value=""<?php checked( $product_filter_stock, false ); ?> /> <?php _e( 'Include both', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="product_filter_stock" value="instock"<?php checked( $product_filter_stock, 'instock' ); ?> /> <?php _e( 'In stock', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="product_filter_stock" value="outofstock"<?php checked( $product_filter_stock, 'outofstock' ); ?> /> <?php _e( 'Out of stock', 'woo_ce' ); ?></label></li>
				</ul>
				<p class="description"><?php _e( 'Select the Stock Status\'s you want to filter exported Products by. Default is to include all Stock Status\'s.', 'woo_ce' ); ?></p>
			</li>

			<li class="export-options order-options">
				<p class="label"><?php _e( 'Order date', 'woo_ce' ); ?></p>
				<ul style="margin-top:0.2em;">
					<li><label><input type="radio" name="order_dates_filter" value=""<?php checked( $order_filter_date, false ); ?> /><?php _e( 'All', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="order_dates_filter" value="today"<?php checked( $order_filter_date, 'today' ); ?> /><?php _e( 'Today', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="order_dates_filter" value="yesterday"<?php checked( $order_filter_date, 'yesterday' ); ?> /><?php _e( 'Yesterday', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="order_dates_filter" value="current_week"<?php checked( $order_filter_date, 'current_week' ); ?> /><?php _e( 'Current week', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="order_dates_filter" value="last_week"<?php checked( $order_filter_date, 'last_week' ); ?> /><?php _e( 'Last week', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="order_dates_filter" value="current_month"<?php checked( $order_filter_date, 'current_month' ); ?> /><?php _e( 'Current month', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="order_dates_filter" value="last_month"<?php checked( $order_filter_date, 'last_month' ); ?> /><?php _e( 'Last month', 'woo_ce' ); ?></label></li>
					<li>
						<label><input type="radio" name="order_dates_filter" value="variable"<?php checked( $order_filter_date, 'variable' ); ?> /><?php _e( 'Variable date', 'woo_ce' ); ?></label>
						<div style="margin-top:0.2em;">
							<?php _e( 'Last', 'woo_ce' ); ?>
							<input type="text" name="order_dates_filter_variable" class="text" size="4" value="<?php echo $order_filter_date_variable; ?>" />
							<select name="order_dates_filter_variable_length">
								<option value=""<?php selected( $order_filter_date_variable_length, '' ); ?>>&nbsp;</option>
								<option value="second"<?php selected( $order_filter_date_variable_length, 'second' ); ?>><?php _e( 'second(s)', 'woo_ce' ); ?></option>
								<option value="minute"<?php selected( $order_filter_date_variable_length, 'minute' ); ?>><?php _e( 'minute(s)', 'woo_ce' ); ?></option>
								<option value="hour"<?php selected( $order_filter_date_variable_length, 'hour' ); ?>><?php _e( 'hour(s)', 'woo_ce' ); ?></option>
								<option value="day"<?php selected( $order_filter_date_variable_length, 'day' ); ?>><?php _e( 'day(s)', 'woo_ce' ); ?></option>
								<option value="week"<?php selected( $order_filter_date_variable_length, 'week' ); ?>><?php _e( 'week(s)', 'woo_ce' ); ?></option>
								<option value="month"<?php selected( $order_filter_date_variable_length, 'month' ); ?>><?php _e( 'month(s)', 'woo_ce' ); ?></option>
								<option value="year"<?php selected( $order_filter_date_variable_length, 'year' ); ?>><?php _e( 'year(s)', 'woo_ce' ); ?></option>
							</select>
						</div>
					</li>
					<li>
						<label><input type="radio" name="order_dates_filter" value="manual"<?php checked( $order_filter_date, 'manual' ); ?> /><?php _e( 'Fixed date', 'woo_ce' ); ?></label>
						<div style="margin-top:0.2em;">
							<input type="text" name="order_dates_from" value="<?php echo $order_filter_dates_from; ?>" size="10" maxlength="10" class="text datepicker" /> to <input type="text" name="order_dates_to" value="<?php echo $order_filter_dates_to; ?>" size="10" maxlength="10" class="text datepicker" />
						</div>
					</li>
					<li>
						<label><input type="radio" name="order_dates_filter" value="last_export"<?php checked( $order_filter_date, 'last_export' ); ?> /> <?php _e( 'Since last export', 'woo_ce' ); ?></label>
						<p class="description"><?php _e( 'Export Orders which have not previously been included in an export. Decided by whether the <code>_woo_cd_exported</code> custom Post meta key has not been assigned to an Order.', 'woo_ce' ); ?></p>
					</li>
				</ul>
				<p class="description"><?php _e( 'Filter the dates of Orders to be included in the export. If manually selecting dates ensure the Fixed date radio field is checked, likewise for variable dates. Default is to include all Orders made in the date format <code>DD/MM/YYYY</code>.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options order-options">
				<p class="label"><?php _e( 'Order status', 'woo_ce' ); ?></p>
<?php if( !empty( $order_statuses ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Order Status...', 'woo_ce' ); ?>" name="order_filter_status[]" multiple class="chzn-select" style="width:95%;">
	<?php foreach( $order_statuses as $order_status ) { ?>
					<option value="<?php echo $order_status->slug; ?>"<?php selected( in_array( $order_status->slug, $order_filter_status ), true ); ?>><?php echo ucfirst( $order_status->name ); ?> (<?php echo $order_status->count; ?>)</option>
	<?php } ?>
				</select>
<?php } else { ?>
				<?php _e( 'No Order Status were found.', 'woo_ce' ); ?>
<?php } ?>
				<p class="description"><?php _e( 'Select the Order Status you want to filter exported Orders by. Default is to include all Order Status options.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options order-options">
				<p class="label"><?php _e( 'Product', 'woo_ce' ); ?></p>
<?php if( wp_script_is( 'wc-enhanced-select', 'enqueued' ) ) { ?>
			<p><input type="hidden" id="order_filter_product" name="order_filter_product[]" class="multiselect wc-product-search" data-multiple="true" style="width:95;" data-placeholder="<?php _e( 'Search for a Product&hellip;', 'woo_ce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-selected="
<?php
	$json_ids = array();
?>
<?php if( !empty( $order_filter_product ) ) { ?>
<?php
	foreach( $order_filter_product as $product_id ) {
		$product = wc_get_product( $product_id );
		if( is_object( $product ) ) {
			$json_ids[$product_id] = wp_kses_post( $product->get_formatted_name() );
		}
	}
	echo esc_attr( json_encode( $json_ids ) ); ?>
<?php } ?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" /></p>
<?php } else { ?>
<?php
	$products = woo_ce_get_products();
	add_filter( 'the_title', 'woo_ce_get_product_title', 10, 2 );
?>
	<?php if( !empty( $products ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Product...', 'woo_ce' ); ?>" name="order_filter_product[]" multiple class="chzn-select" style="width:95%;">
		<?php foreach( $products as $product ) { ?>
					<option value="<?php echo $product; ?>"<?php selected( in_array( $product, $order_filter_product ), true ); ?>><?php echo get_the_title( $product ); ?></option>
		<?php } ?>
				</select>
	<?php } else { ?>
				<?php _e( 'No Products were found.', 'woo_ce' ); ?>
	<?php } ?>
<?php
	remove_filter( 'the_title', 'woo_ce_get_product_title' );
?>
<?php } ?>
				<p class="description"><?php _e( 'Select the Products you want to filter exported Orders by. Default is to include all Products.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options order-options">
				<p class="label"><?php _e( 'Billing country', 'woo_ce' ); ?></p>
<?php if( !empty( $countries ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Billing Country...', 'woo_ce' ); ?>" name="order_filter_billing_country[]" multiple class="chzn-select" style="width:95%;">
					<option value=""><?php _e( 'Show all Countries', 'woo_ce' ); ?></option>
	<?php foreach( $countries as $country_prefix => $country ) { ?>
					<option value="<?php echo $country_prefix; ?>"<?php selected( in_array( $country_prefix, $order_filter_billing_country ), true ); ?>><?php printf( '%s (%s)', $country, $country_prefix ); ?></option>
	<?php } ?>
				</select>
<?php } else { ?>
				<p><?php _e( 'No Countries were found.', 'woo_ce' ); ?></p>
<?php } ?>
				<p class="description"><?php _e( 'Filter Orders by Billing Country to be included in the export. Default is to include all Countries.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options order-options">
				<p class="label"><?php _e( 'Shipping country', 'woo_ce' ); ?></p>
<?php if( !empty( $countries ) ) { ?>
				<select id="order_filter_shipping_country" data-placeholder="<?php _e( 'Choose a Shipping Country...', 'woo_ce' ); ?>" name="order_filter_shipping_country[]" multiple class="chzn-select" style="width:95%;">
					<option value=""><?php _e( 'Show all Countries', 'woo_ce' ); ?></option>
	<?php foreach( $countries as $country_prefix => $country ) { ?>
					<option value="<?php echo $country_prefix; ?>"<?php selected( in_array( $country_prefix, $order_filter_shipping_country ), true ); ?>><?php printf( '%s (%s)', $country, $country_prefix ); ?></option>
	<?php } ?>
				</select>
<?php } else { ?>
				<p><?php _e( 'No Countries were found.', 'woo_ce' ); ?></p>
<?php } ?>
				<p class="description"><?php _e( 'Filter Orders by Shipping Country to be included in the export. Default is to include all Countries.', 'woo_ce' ); ?></p>
			</li>

			<li class="export-options order-options">
				<p class="label"><?php _e( 'Payment gateway', 'woo_ce' ); ?></p>
<?php if( !empty( $payment_gateways ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Payment Gateway...', 'woo_ce' ); ?>" name="order_filter_payment[]" multiple class="chzn-select" style="width:95%;">
	<?php foreach( $payment_gateways as $payment_gateway ) { ?>
					<option value="<?php echo $payment_gateway->id; ?>"<?php selected( in_array( $payment_gateway->id, $order_filter_payment ), true ); ?>><?php echo ucfirst( woo_ce_format_order_payment_gateway( $payment_gateway->id ) ); ?></option>
	<?php } ?>
				</select>
<?php } else { ?>
				<?php _e( 'No Payment Gateways were found.', 'woo_ce' ); ?>
<?php } ?>
				<p class="description"><?php _e( 'Select the Payment Gateways you want to filter exported Orders by. Default is to include all Payment Gateways.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options order-options">
				<p class="label"><?php _e( 'Shipping method', 'woo_ce' ); ?></p>
<?php if( !empty( $shipping_methods ) ) { ?>
				<select data-placeholder="<?php _e( 'Choose a Shipping Method...', 'woo_ce' ); ?>" name="order_filter_shipping[]" multiple class="chzn-select" style="width:95%;">
	<?php foreach( $shipping_methods as $shipping_method ) { ?>
					<option value="<?php echo $shipping_method->id; ?>"<?php selected( in_array( $shipping_method->id, $order_filter_shipping ), true ); ?>><?php echo ucfirst( woo_ce_format_order_shipping_method( $shipping_method->id ) ); ?></option>
	<?php } ?>
				</select>
<?php } else { ?>
				<?php _e( 'No Shipping Methods were found.', 'woo_ce' ); ?>
<?php } ?>
				<p class="description"><?php _e( 'Select the Shipping Methods you want to filter exported Orders by. Default is to include all Shipping Methods.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li class="export-options category-options tag-options brand-options customer-options user-options coupon-options subscription-options product_vendor-options commission-options shipping_class-options">
				<p><?php _e( 'No export filter options are available for this export type.', 'woo_ce' ); ?></p>
			</li>

		</ul>
	</td>
</tr>

<tr>
	<th>
		<label><?php _e( 'Scheduling', 'woo_ce' ); ?></label>
	</th>
	<td>
		<p><?php _e( 'How often do you want the export to run?', 'woo_ce' ); ?></p>
		<ul>
			<li>
				<label><input type="radio" name="auto_schedule" value="custom"<?php checked( $auto_schedule, 'custom' ); ?> /> <?php _e( 'Once every ', 'woo_ce' ); ?></label>
				<input name="auto_interval" type="text" id="auto_interval" value="<?php echo esc_attr( $auto_interval ); ?>" size="6" maxlength="6" class="text" />
				<?php _e( 'minutes', 'woo_ce' ); ?>
			</li>
			<li><label><input type="radio" name="auto_schedule" value="daily"<?php checked( $auto_schedule, 'daily' ); ?> /> <?php _e( 'Daily', 'woo_ce' ); ?></label></li>
			<li><label><input type="radio" name="auto_schedule" value="weekly"<?php checked( $auto_schedule, 'weekly' ); ?> /> <?php _e( 'Weekly', 'woo_ce' ); ?></label></li>
			<li><label><input type="radio" name="auto_schedule" value="monthly"<?php checked( $auto_schedule, 'monthly' ); ?> /> <?php _e( 'Monthly', 'woo_ce' ); ?></label></li>
			<li><label><input type="radio" name="auto_schedule" value="one-time" /> <?php _e( 'One time', 'woo_ce' ); ?></label></li>
		</ul>
		<p class="description"><?php _e( 'Choose how often Store Exporter Deluxe generates new exports. Default is every 1440 minutes (once every 24 hours).', 'woo_ce' ); ?></p>
		<hr />
		<p><?php _e( 'When do you want scheduled exports to start?', 'woo_ce' ); ?></p>
		<ul>
			<li><label><input type="radio" name="auto_commence" value="now"<?php checked( $auto_commence, 'now' ); ?> /><?php _e( 'From now', 'woo_ce' ); ?></label></li>
			<li><label><input type="radio" name="auto_commence" value="future"<?php checked( $auto_commence, 'future' ); ?> /><?php _e( 'From the following', 'woo_ce' ); ?></label>: <input type="text" name="auto_commence_date" size="20" maxlength="20" class="text datetimepicker" value="<?php echo $auto_commence_date; ?>" /><!--, <?php _e( 'at this time', 'woo_ce' ); ?>: <input type="text" name="auto_interval_time" size="10" maxlength="10" class="text timepicker" />--></li>
		</ul>
	</td>
</tr>

<tr>
	<th>
		<label><?php _e( 'Export format', 'woo_ce' ); ?></label>
	</th>
	<td>
		<ul style="margin-top:0.2em;">
			<li><label><input type="radio" name="auto_format" value="csv"<?php checked( $auto_format, 'csv' ); ?> /> <?php _e( 'CSV', 'woo_ce' ); ?> <span class="description"><?php _e( '(Comma Separated Values)', 'woo_ce' ); ?></span></label></li>
			<li><label><input type="radio" name="auto_format" value="xml"<?php checked( $auto_format, 'xml' ); ?> /> <?php _e( 'XML', 'woo_ce' ); ?> <span class="description"><?php _e( '(EXtensible Markup Language)', 'woo_ce' ); ?></span></label></li>
			<li><label><input type="radio" name="auto_format" value="xls"<?php checked( $auto_format, 'xls' ); ?> /> <?php _e( 'Excel (XLS)', 'woo_ce' ); ?> <span class="description"><?php _e( '(Excel 97-2003)', 'woo_ce' ); ?></span></label></li>
			<li><label><input type="radio" name="auto_format" value="xlsx"<?php checked( $auto_format, 'xlsx' ); ?> /> <?php _e( 'Excel (XLSX)', 'woo_ce' ); ?> <span class="description"><?php _e( '(Excel 2007-2013)', 'woo_ce' ); ?></span></label></li>
		</ul>
		<p class="description"><?php _e( 'Adjust the export format to generate different export file formats. Default is CSV.', 'woo_ce' ); ?></p>
	</td>
</tr>

<tr>
	<th>
		<label for="auto_method"><?php _e( 'Export method', 'woo_ce' ); ?></label>
	</th>
	<td>
		<select id="auto_method" name="auto_method">
			<option value="archive"<?php selected( $auto_method, 'archive' ); ?>><?php _e( 'Archive to WordPress Media', 'woo_ce' ); ?></option>
			<option value="email"<?php selected( $auto_method, 'email' ); ?>><?php _e( 'Send as e-mail', 'woo_ce' ); ?></option>
			<option value="post"<?php selected( $auto_method, 'post' ); ?>><?php _e( 'POST to remote URL', 'woo_ce' ); ?></option>
			<option value="ftp"<?php selected( $auto_method, 'ftp' ); ?>><?php _e( 'Upload to remote FTP/SFTP', 'woo_ce' ); ?></option>
		</select>
		<p class="description"><?php _e( 'Choose what Store Exporter Deluxe does with the generated export. Default is to archive the export to the WordPress Media for archival purposes.', 'woo_ce' ); ?></p>
	</td>
</tr>
<tr class="auto_method_options">
	<th>
		<label><?php _e( 'Export method options', 'woo_ce' ); ?></label>
	</th>
	<td>
		<ul>

			<li class="export-options email-options">
				<p>
					<label for="email_to"><?php _e( 'Default e-mail recipient', 'woo_ce' ); ?></label><br />
					<input name="email_to" type="text" id="email_to" value="<?php echo esc_attr( $email_to ); ?>" class="large-text code" />
				</p>
				<p class="description"><?php _e( 'Set the default recipient of scheduled export e-mails, multiple recipients can be added using the <code><attr title="comma">,</attr></code> separator. This option can be overriden via CRON using the <code>to</code> argument.<br />Default is the Blog Administrator e-mail address set on the WordPress &raquo; Settings screen.', 'woo_ce' ); ?></p>

				<p>
					<label for="email_subject"><?php _e( 'Default e-mail subject', 'woo_ce' ); ?></label><br />
					<input name="email_subject" type="text" id="email_subject" value="<?php echo esc_attr( $email_subject ); ?>" class="large-text code" />
				</p>
				<p class="description"><?php _e( 'Set the default subject of scheduled export e-mails, can be overriden via CRON using the <code>subject</code> argument. Tags can be used: <code>%store_name%</code>, <code>%export_type%</code>, <code>%export_filename%</code>.', 'woo_ce' ); ?></p>
			</li>

			<li class="export-options post-options">
				<p>
					<label for="post_to"><?php _e( 'Default remote POST URL', 'woo_ce' ); ?></label><br />
					<input name="post_to" type="text" id="post_to" value="<?php echo esc_url( $post_to ); ?>" class="large-text code" />
				</p>
				<p class="description"><?php printf( __( 'Set the default remote POST address for scheduled exports, can be overriden via CRON using the <code>to</code> argument. Default is empty. See our <a href="%s" target="_blank">Usage</a> document for more information on Default remote POST URL.', 'woo_ce' ), $troubleshooting_url ); ?></p>
			</li>

			<li class="export-options ftp-options">
				<label for="ftp_method_host"><?php _e( 'Host', 'woo_ce' ); ?>:</label> <input type="text" id="ftp_method_host" name="ftp_method_host" size="15" class="regular-text code" value="<?php echo sanitize_text_field( $ftp_method_host ); ?>" />&nbsp;
				<label for="ftp_method_port" style="width:auto;"><?php _e( 'Port', 'woo_ce' ); ?>:</label> <input type="text" id="ftp_method_port" name="ftp_method_port" size="5" class="short-text code" value="<?php echo sanitize_text_field( $ftp_method_port ); ?>" maxlength="5" /><br />
				<label for="ftp_method_protocol"><?php _e( 'Protocol', 'woo_ce' ); ?>:</label>
				<select name="ftp_method_protocol">
					<option value="ftp"<?php selected( $ftp_method_protocol, 'ftp' ); ?>><?php _e( 'FTP - File Transfer Protocol', 'woo_ce' ); ?></option>
					<option value="sftp"<?php selected( $ftp_method_protocol, 'sftp' ); ?><?php disabled( ( !function_exists( 'ssh2_connect' ) ? true : false ), true ); ?>><?php _e( 'SFTP - SSH File Transfer Protocol', 'woo_ce' ); ?></option>
				</select><br />
				<label for="ftp_method_user"><?php _e( 'Username', 'woo_ce' ); ?>:</label> <input type="text" id="ftp_method_user" name="ftp_method_user" size="15" class="regular-text code" value="<?php echo sanitize_text_field( $ftp_method_user ); ?>" /><br />
				<label for="ftp_method_pass"><?php _e( 'Password', 'woo_ce' ); ?>:</label> <input type="password" id="ftp_method_pass" name="ftp_method_pass" size="15" class="regular-text code" value="" /><?php if( !empty( $ftp_method_pass ) ) { echo ' ' . __( '(password is saved, fill this field to change it)', 'woo_ce' ); } ?><br />
				<label for="ftp_method_file_path"><?php _e( 'File path', 'woo_ce' ); ?>:</label> <input type="text" id="ftp_method_file_path" name="ftp_method_path" size="25" class="regular-text code" value="<?php echo sanitize_text_field( $ftp_method_path ); ?>" /><br />
				<label for="ftp_method_filename"><?php _e( 'Fixed filename', 'woo_ce' ); ?>:</label> <input type="text" id="ftp_method_filename" name="ftp_method_filename" size="25" class="regular-text code" value="<?php echo sanitize_text_field( $ftp_method_filename ); ?>" /><br />
				<label for="ftp_method_passive"><?php _e( 'Transfer mode', 'woo_ce' ); ?>:</label> 
				<select id="ftp_method_passive" name="ftp_method_passive">
					<option value="auto"<?php selected( $ftp_method_passive, '' ); ?>><?php _e( 'Auto', 'woo_ce' ); ?></option>
					<option value="active"<?php selected( $ftp_method_passive, 'active' ); ?>><?php _e( 'Active', 'woo_ce' ); ?></option>
					<option value="passive"<?php selected( $ftp_method_passive, 'passive' ); ?>><?php _e( 'Passive', 'woo_ce' ); ?></option>
				</select><br />
				<label for="ftp_method_timeout"><?php _e( 'Timeout', 'woo_ce' ); ?>:</label> <input type="text" id="ftp_method_timeout" name="ftp_method_timeout" size="5" class="short-text code" value="<?php echo sanitize_text_field( $ftp_method_timeout ); ?>" /><br />
				<p class="description">
					<?php _e( 'Enter the FTP host (minus <code>ftp://</code>), login details and path of where to save the export file, do not provide the filename within File path. For file path example: <code>wp-content/uploads/exports/</code><br />The export filename can be set within the Fixed filename field otherwise it defaults to the Export filename provided within General Settings above. Tags can be used: ', 'woo_ce' ); ?> <code>%dataset%</code>, <code>%date%</code>, <code>%time%</code>, <code>%store_name%</code>.
<?php if( !function_exists( 'ssh2_connect' ) ) { ?>
					<br /><?php _e( 'The SFTP - SSH File Transfer Protocol option is not available as the required function ssh2_connect() is disabled within your WordPress site.', 'woo_ce' ); ?></p>
<?php } ?>
				</p>
			</li>

			<li class="export-options archive-options">
				<p><?php _e( 'No export method options are available for this export method.', 'woo_ce' ); ?></p>
			</li>

		</ul>
	</td>
</tr>
<tr>
	<th>
		<label for="scheduled_fields"><?php _e( 'Export fields', 'woo_ce' ); ?></label>
	</th>
	<td>
		<ul style="margin-top:0.2em;">
			<li><label><input type="radio" id="scheduled_fields" name="scheduled_fields" value="all"<?php checked( $scheduled_fields, 'all' ); ?> /> <?php _e( 'Include all Export Fields for the requested Export Type', 'woo_ce' ); ?></label></li>
			<li><label><input type="radio" name="scheduled_fields" value="saved"<?php checked( $scheduled_fields, 'saved' ); ?> /> <?php _e( 'Use the saved Export Fields preference set on the Export screen for the requested Export Type', 'woo_ce' ); ?></label></li>
		</ul>
		<p class="description"><?php _e( 'Control whether all known export fields are included or only checked fields from the Export Fields section on the Export screen for each Export Type. Default is to include all export fields.', 'woo_ce' ); ?></p>
	</td>
</tr>

<tr id="cron-exports">
	<td colspan="2" style="padding:0;">
		<hr />
		<h3><div class="dashicons dashicons-clock"></div>&nbsp;<?php _e( 'CRON Exports', 'woo_ce' ); ?></h3>
<?php if( $enable_cron == 1 ) { ?>
		<p style="font-size:0.8em;"><div class="dashicons dashicons-yes"></div>&nbsp;<strong><?php _e( 'CRON Exports is enabled', 'woo_ce' ); ?></strong></p>
<?php } ?>
		<p class="description"><?php printf( __( 'Store Exporter Deluxe supports exporting via a command line request, to do this you need to prepare a specific URL and pass it the following required inline parameters. For sample CRON requests and supported arguments consult our <a href="%s" target="_blank">online documentation</a>.', 'woo_ce' ), $troubleshooting_url ); ?></p>
	</td>
</tr>
<tr>
	<th>
		<label for="enable_cron"><?php _e( 'Enable CRON', 'woo_ce' ); ?></label>
	</th>
	<td>
		<select id="enable_cron" name="enable_cron">
			<option value="1"<?php selected( $enable_cron, 1 ); ?>><?php _e( 'Yes', 'woo_ce' ); ?></option>
			<option value="0"<?php selected( $enable_cron, 0 ); ?>><?php _e( 'No', 'woo_ce' ); ?></option>
		</select>
		<p class="description"><?php _e( 'Enabling CRON allows developers to schedule automated exports and connect with Store Exporter Deluxe remotely.', 'woo_ce' ); ?></p>
	</td>
</tr>
<tr>
	<th>
		<label for="secret_key"><?php _e( 'Export secret key', 'woo_ce' ); ?></label>
	</th>
	<td>
		<input name="secret_key" type="text" id="secret_key" value="<?php echo esc_attr( $secret_key ); ?>" class="large-text code" />
		<p class="description"><?php _e( 'This secret key (can be left empty to allow unrestricted access) limits access to authorised developers who provide a matching key when working with Store Exporter Deluxe.', 'woo_ce' ); ?></p>
	</td>
</tr>
<tr>
	<th>
		<label for="cron_fields"><?php _e( 'Export fields', 'woo_ce' ); ?></label>
	</th>
	<td>
		<ul style="margin-top:0.2em;">
			<li><label><input type="radio" id="cron_fields" name="cron_fields" value="all"<?php checked( $cron_fields, 'all' ); ?> /> <?php _e( 'Include all Export Fields for the requested Export Type', 'woo_ce' ); ?></label></li>
			<li><label><input type="radio" name="cron_fields" value="saved"<?php checked( $cron_fields, 'saved' ); ?> /> <?php _e( 'Use the saved Export Fields preference set on the Export screen for the requested Export Type', 'woo_ce' ); ?></label></li>
		</ul>
		<p class="description"><?php _e( 'Control whether all known export fields are included or only checked fields from the Export Fields section on the Export screen for each Export Type. Default is to include all export fields.', 'woo_ce' ); ?></p>
	</td>
</tr>

<tr id="orders-screen">
	<td colspan="2" style="padding:0;">
		<hr />
		<h3><div class="dashicons dashicons-admin-settings"></div>&nbsp;<?php _e( 'Orders Screen', 'woo_ce' ); ?></h3>
	</td>
</tr>
<tr>
	<th>
		<label><?php _e( 'Actions display', 'woo_ce' ); ?></label>
	</th>
	<td>
		<ul>
			<li><label><input type="checkbox" name="order_actions_csv" value="1"<?php checked( $order_actions_csv ); ?> /> <?php _e( 'Export to CSV', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="order_actions_xml" value="1"<?php checked( $order_actions_xml ); ?> /> <?php _e( 'Export to XML', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="order_actions_xls" value="1"<?php checked( $order_actions_xls ); ?> /> <?php _e( 'Export to XLS', 'woo_ce' ); ?></label></li>
			<li><label><input type="checkbox" name="order_actions_xlsx" value="1"<?php checked( $order_actions_xlsx ); ?> /> <?php _e( 'Export to XLSX', 'woo_ce' ); ?></label></li>
		</ul>
		<p class="description"><?php _e( 'Control the visibility of different Order actions on the WooCommerce &raquo; Orders screen.', 'woo_ce' ); ?></p>
	</td>
</tr>

<tr id="export-triggers">
	<td colspan="2" style="padding:0;">
		<hr />
		<h3><div class="dashicons dashicons-admin-settings"></div>&nbsp;<?php _e( 'Export Triggers', 'woo_ce' ); ?></h3>
		<p class="description"><?php _e( 'Configure Store Exporter Deluxe to run exports on specific triggers within your WooCommerce store.', 'woo_ce' ); ?></p>
	</td>
</tr>

<tr>
	<th>
		<label><?php _e( 'New Order', 'woo_ce' ); ?></label>
	</th>
	<td>
<?php if( $enable_trigger_new_order == 1 ) { ?>
		<p style="font-size:0.8em;"><div class="dashicons dashicons-yes"></div>&nbsp;<strong><?php _e( 'Export on New Order is enabled, this will run for each new Order received.', 'woo_ce' ); ?></strong></p>
<?php } ?>
		<p class="description"><?php _e( 'Trigger an export of each new Order that is generated after successful Checkout.', 'woo_ce' ); ?></p>
		<ul>

			<li>
				<p>
					<label for="enable_trigger_new_order"><?php _e( 'Enable trigger', 'woo_ce' ); ?></label><br />
					<select id="enable_trigger_new_order" name="enable_trigger_new_order">
						<option value="1"<?php selected( $enable_trigger_new_order, 1 ); ?>><?php _e( 'Yes', 'woo_ce' ); ?></option>
						<option value="0"<?php selected( $enable_trigger_new_order, 0 ); ?>><?php _e( 'No', 'woo_ce' ); ?></option>
					</select>
				</p>
				<hr />
			</li>

			<li>
				<p><label><?php _e( 'Export format', 'woo_ce' ); ?></label></p>
				<ul style="margin-top:0.2em;">
					<li><label><input type="radio" name="trigger_new_order_format" value="csv"<?php checked( $trigger_new_order_format, 'csv' ); ?> /> <?php _e( 'CSV', 'woo_ce' ); ?> <span class="description"><?php _e( '(Comma Separated Values)', 'woo_ce' ); ?></span></label></li>
					<li><label><input type="radio" name="trigger_new_order_format" value="xml"<?php checked( $trigger_new_order_format, 'xml' ); ?> /> <?php _e( 'XML', 'woo_ce' ); ?> <span class="description"><?php _e( '(EXtensible Markup Language)', 'woo_ce' ); ?></span></label></li>
					<li><label><input type="radio" name="trigger_new_order_format" value="xls"<?php checked( $trigger_new_order_format, 'xls' ); ?> /> <?php _e( 'Excel (XLS)', 'woo_ce' ); ?> <span class="description"><?php _e( '(Excel 97-2003)', 'woo_ce' ); ?></span></label></li>
					<li><label><input type="radio" name="trigger_new_order_format" value="xlsx"<?php checked( $trigger_new_order_format, 'xlsx' ); ?> /> <?php _e( 'Excel (XLSX)', 'woo_ce' ); ?> <span class="description"><?php _e( '(Excel 2007-2013)', 'woo_ce' ); ?></span></label></li>
				</ul>
				<hr />
			</li>

			<li>
				<p><label><?php _e( 'Export method', 'woo_ce' ); ?></label></p>
				<select id="trigger_new_order_method" name="trigger_new_order_method">
					<option value="archive"<?php selected( $trigger_new_order_method, 'archive' ); ?>><?php _e( 'Archive to WordPress Media', 'woo_ce' ); ?></option>
<!--
					<option value="email"<?php selected( $trigger_new_order_method, 'email' ); ?>><?php _e( 'Send as e-mail', 'woo_ce' ); ?></option>
					<option value="post"<?php selected( $trigger_new_order_method, 'post' ); ?>><?php _e( 'POST to remote URL', 'woo_ce' ); ?></option>
					<option value="ftp"<?php selected( $trigger_new_order_method, 'ftp' ); ?>><?php _e( 'Upload to remote FTP/SFTP', 'woo_ce' ); ?></option>
-->
				</select>
				<hr />
			</li>

			<li>
				<p><label><?php _e( 'Export method options', 'woo_ce' ); ?></label></p>
				<p><?php _e( 'No export method options are available for this export method.', 'woo_ce' ); ?></p>
				<hr />
			</li>

			<li>
				<p><label><?php _e( 'Export fields', 'woo_ce' ); ?></label></p>
				<ul style="margin-top:0.2em;">
					<li><label><input type="radio" id="trigger_new_order_fields" name="trigger_new_order_fields" value="all"<?php checked( $trigger_new_order_fields, 'all' ); ?> /> <?php _e( 'Include all Order Fields', 'woo_ce' ); ?></label></li>
					<li><label><input type="radio" name="trigger_new_order_fields" value="saved"<?php checked( $trigger_new_order_fields, 'saved' ); ?> /> <?php _e( 'Use the saved Export Fields preference for Orders set on the Export screen', 'woo_ce' ); ?></label></li>
				</ul>
				<p class="description"><?php _e( 'Control whether all known export fields are included or only checked fields from the Export Fields section on the Export screen for Orders. Default is to include all export fields.', 'woo_ce' ); ?></p>
			</li>

		</ul>
	</td>
</tr>

<?php
	ob_end_flush();

}