Copy ‘Export’ button to frontend
-
Hi,
Your plugin is really great but I’m wondering about one function I really need.
It is possible to add button “Export” (same as in back-end “Export now” tab in plugin settings) to the front-end?
I mean I need to create blank page e.g http://my-site.com/new-page/ with ‘copy’ of the Export button from back-end connected with back-end settings.
Is there a fast way to do sth like this?
Thanks you, Tomek.
-
Hi Tomek
Please, you must add code for this button (in backend ) and call this code to make file
$_REQUEST['profile'] = 'now'; WC_Order_Export_Ajax::run_one_job();I made the button on my page which is calling the code you write but nothing is happening :/
Here is my code:<form method="post"> <input type="submit" name="test" id="test" value="Export" /> </form> <?php if(array_key_exists('test',$_POST)){ $_REQUEST['profile'] = 'now'; WC_Order_Export_Ajax::run_one_job(); } ?>-
This reply was modified 6 years, 11 months ago by
piwowartomek.
-
This reply was modified 6 years, 11 months ago by
piwowartomek.
Where did you put php code ? inside page ?
I think you should use something like this code and put it in functions.php
add_action( 'parse_request', function( $query ) { if ( array_key_exists('test',$_POST) ) { $_REQUEST['profile'] = 'now'; WC_Order_Export_Ajax::run_one_job(); die(); } return $query; });Thanks for quick reply. Now I have this code in page template:
<form method="post"> <input type="submit" name="exportAllOrders" id="exportAllOrders" value="Export" /> </form>And this in functions.php:
add_action( 'parse_request', function( $query ) { if ( array_key_exists('exportAllOrders',$_POST) ) { $_REQUEST['profile'] = 'now'; WC_Order_Export_Ajax::run_one_job(); die(); } return $query; });But my new button still cause HTTP ERROR 500 instead of download file.
-
This reply was modified 6 years, 11 months ago by
piwowartomek.
please, remove php code and use this form
<form method="get" action="/wp-admin/admin-ajax.php"> <input type="hidden" name="action" value="order_exporter"> <input type="hidden" name="method" value="run_one_job"> <input type="hidden" name="profile" value="now"> <input type="submit" name="exportAllOrders" id="exportAllOrders" value="Export"> </form>Works great!
Thank you for your superb feedback.you’re welcome
if i wanted to create a couple of profiles which i can modify the html form all ok for variable user select form
what would i need to do to parse the variable to the php function ?
i.e
WC_Order_Export_Ajax::run_one_job(“PASSED_VARIABLE”); ????Thanks
use this version
<form method="get" action="/wp-49/wp-admin/admin-ajax.php"> <input type="hidden" name="action" value="order_exporter"> <input type="hidden" name="method" value="run_one_job"> <select name="profile"> <option>now</option> <option>1</option> <option>2</option> </select> <input type="submit" name="exportAllOrders" id="exportAllOrders" value="Export"> </form>when you edit profile you will see profile ID in the url , like …edit_profile&profile_id=XXX
-
This reply was modified 6 years, 11 months ago by
algol.plus.
ok so this only works if you are logged in as admin š
You must give this user capability “view_woocommerce_reports”.
-
This reply was modified 6 years, 11 months ago by
algol.plus.
I have already export button on the frontend:
<form method="get" action="/wp-admin/admin-ajax.php"> <input type="hidden" name="action" value="order_exporter"> <input type="hidden" name="method" value="run_one_job"> <input type="hidden" name="profile" value="now"> <input type="submit" name="exportAllOrders" id="exportAllOrders" value="Export"> </form>Is it also possible to copy to frontend “Date range” section from dashboard with two date pickers (from & to) to allow user select date range?
Btw. Why the “Date range” section exports order data not <from -> to> picked dates, but from one day after and to one day before I picked in input?
Updated form
<form method="get" action="/wp-49/wp-admin/admin-ajax.php"> <input type="hidden" name="action" value="order_exporter"> <input type="text" class="hasDatepicker" name="from_date" value=""> <input type="text" class="hasDatepicker" name="to_date" value=""> <input type="hidden" name="method" value="run_one_job"> <input type="hidden" name="profile" value="now"> <input type="submit" name="exportAllOrders" id="exportAllOrders" value="Export"> </form>+ you must add this code to functions.php
add_filter('woe_settings_validate_defaults', function($settings){ if( !empty($_GET['from_date']) ) $settings['from_date'] = $_GET['from_date']; if( !empty($_GET['to_date']) ) $settings['to_date'] = $_GET['to_date']; return $settings; });but I can’t help you with datepickers.
About wrong date range – probably, mysql and webserver use different timezones.
We’ve already fixed this bug in beta. -
This reply was modified 6 years, 11 months ago by
The topic ‘Copy ‘Export’ button to frontend’ is closed to new replies.