Skip to content

Commit

Permalink
Add export ajax query args and filename filter hooks
Browse files Browse the repository at this point in the history
`woocommerce_export_get_ajax_query_args` let you pass args to ajax actions
`woocommerce_{$this->export_type}_export_get_filename` let you change the filename
  • Loading branch information
AdamQuadmon committed Dec 20, 2017
1 parent 865efa3 commit 1b42973
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion includes/admin/class-wc-admin-exporters.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ public function do_ajax_product_export() {
$exporter->set_page( $step );
$exporter->generate_file();

$query_args = apply_filters( 'woocommerce_export_get_ajax_query_args', array( 'nonce' => wp_create_nonce( 'product-csv' ), 'action' => 'download_product_csv' ) );

if ( 100 === $exporter->get_percent_complete() ) {
wp_send_json_success( array(
'step' => 'done',
'percentage' => 100,
'url' => add_query_arg( array( 'nonce' => wp_create_nonce( 'product-csv' ), 'action' => 'download_product_csv' ), admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
'url' => add_query_arg( $query_args, admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
) );
} else {
wp_send_json_success( array(
Expand Down
4 changes: 3 additions & 1 deletion includes/export/abstract-wc-csv-exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ public function send_headers() {
* @return string
*/
public function get_filename() {
return sanitize_file_name( 'wc-' . $this->export_type . '-export-' . date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) . '.csv' );
$filename = 'wc-' . $this->export_type . '-export-' . date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) . '.csv';

return sanitize_file_name( apply_filters( "woocommerce_{$this->export_type}_export_get_filename", $filename ) );
}

/**
Expand Down

0 comments on commit 1b42973

Please sign in to comment.