admin_url( 'admin-ajax.php')); ?>
$val ){ ?>

admin_url( 'admin-ajax.php'))); } add_action('wp_ajax_awe_orderdetails', 'awe_orderdetails'); add_action('wp_ajax_nopriv_awe_orderdetails', 'awe_orderdetails'); function awe_orderdetails(){ $awe_postresult = stripslashes($_POST['search_val']); $awe_dataresult = json_decode($awe_postresult); $awe_result = count($awe_dataresult); /** Set default timezone (will throw a notice otherwise) */ //date_default_timezone_set('Asia/Kolkata'); // include PHPExcel require('PHPExcel.php'); // create new PHPExcel object $objPHPExcel = new PHPExcel(); // set default font $objPHPExcel->getDefaultStyle()->getFont()->setName('Calibri'); // set default font size $objPHPExcel->getDefaultStyle()->getFont()->setSize(10); // create the writer $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007"); /** * Define currency and number format. */ // currency format, € with < 0 being in red color $currencyFormat = '#,#0.## \€;[Red]-#,#0.## \€'; // number format, with thousands separator and two decimal points. $numberFormat = '#,#0.##;[Red]-#,#0.##'; // writer already created the first sheet for us, let's get it $objSheet = $objPHPExcel->getActiveSheet(); // rename the sheet $objSheet->setTitle('My sales report'); // let's bold and size the header font and write the header // as you can see, we can specify a range of cells, like here: cells from A1 to A4 $objSheet->getStyle('A1')->getFont()->setBold(true)->setSize(12); $i=0; // For get how many results get in array $j=0; // For Header Display for ($char = 'B'; $char <= 'Z'; $char++) { $i++; if($awe_result >= $i){ $objSheet->getStyle($char.'1')->getFont()->setBold(true)->setSize(12); } } // write header $objSheet->getCell('A1')->setValue('No'); $k=0; // For Get how many results get in array for ($char1 = 'B'; $char1 <= 'Z'; $char1++) { $k++; if($awe_result >= $k){ $textvl1 = $awe_dataresult[$j]->rel; $objSheet->getCell($char1.'1')->setValue($textvl1); } $j++; } // we could get this data from database, but here we are writing for simplicity $filters = array( 'post_status' => 'public', 'post_type' => 'shop_order', 'posts_per_page' => 200, 'paged' => 1 ); $loop = new WP_Query($filters); $q = 1; // For Numbering Details $p = 2; // For Row counting while ($loop->have_posts()) { $loop->the_post(); $order = new WC_Order($loop->post->ID); $all_order = $order->get_items(); foreach ($order->get_items() as $key => $lineItem) { $ordera = wc_get_order( $lineItem['order_id'] ); $order_data = $ordera->get_data(); $id = $q++; $p++; $objSheet->getCell('A'.$p)->setValue($id); $s=0; $d=0; for ($char2 = 'B'; $char2 <= 'Z'; $char2++) { $s++; if($awe_result >= $s){ $textvl = $awe_dataresult[$d]->value; if($textvl == 'order_id'){ $data = $lineItem['order_id']; } elseif($textvl == 'order_status'){ $data = $order_data['status']; } else { $data = get_post_meta( $lineItem['order_id'], $textvl, true ); } $objSheet->getCell($char2.$p)->setValue($data); } $d++; } } } // autosize the columns $e=0; //For get how many results get in array for ($char3 = 'A'; $char3 <= 'Z'; $char3++) { $e++; if($awe_result >= $e){ $objSheet->getColumnDimension($char3)->setAutoSize(true); } } $fileName = dirname(__FILE__).'/order.xlsx'; header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename=order.xlsx'); header('Cache-Control: max-age=0'); // Clear any previous output $cre = $objWriter->save($fileName); //$objWriter->save('php://output'); } //Add Style Sheet in Backend add_action( 'admin_print_styles', 'awe_styles_admin' ); function awe_styles_admin() { wp_enqueue_style( 'thickbox' ); wp_enqueue_style( 'stylesheet', plugins_url('css/allwoocommerceexport.css' , __FILE__ ), array(), '', false ); } //Uninstall Plugin register_deactivation_hook('__FILE__', 'awe_uninstall'); function awe_uninstall() { delete_option('all_woocommerceexport'); } ?>