/** * Processes the 'Download to CSV' custom bulk action on the 'Orders' page bulk action drop-down * * @since 3.0 */ public function process_order_bulk_actions() { global $typenow; if ('shop_order' == $typenow) { // get the action $wp_list_table = _get_list_table('WP_Posts_List_Table'); $action = $wp_list_table->current_action(); // return if not processing our actions if (!in_array($action, array('download_to_csv', 'mark_exported', 'mark_not_exported'))) { return; } // security check check_admin_referer('bulk-posts'); // make sure order IDs are submitted if (isset($_REQUEST['post'])) { $order_ids = array_map('absint', $_REQUEST['post']); } // return if there are no orders to export if (empty($order_ids)) { return; } // give ourselves an unlimited timeout if possible @set_time_limit(0); if ('download_to_csv' == $action) { // setup export class $export = new WC_Customer_Order_CSV_Export_Handler($order_ids); $export->download(); } else { // mark each order as exported / not exported foreach ($order_ids as $order_id) { update_post_meta($order_id, '_wc_customer_order_csv_export_is_exported', 'mark_exported' == $action ? 1 : 0); } } } }
/** * Downloads order in CSV format (from order action button on 'Orders' page) * * @since 3.0 */ public function process_ajax_export_order() { if (!is_admin() || !current_user_can('edit_posts')) { wp_die(__('You do not have sufficient permissions to access this page.', WC_Customer_Order_CSV_Export::TEXT_DOMAIN)); } if (!check_admin_referer('wc_customer_order_csv_export_export_order')) { wp_die(__('You have taken too long, please go back and try again.', WC_Customer_Order_CSV_Export::TEXT_DOMAIN)); } $order_id = !empty($_GET['order_id']) ? absint($_GET['order_id']) : ''; if (!$order_id) { die; } $export = new WC_Customer_Order_CSV_Export_Handler($order_id); $export->download(); wp_redirect(wp_get_referer()); exit; }