Skip to content

Instantly share code, notes, and snippets.

@tamarazuk
Last active August 29, 2015 14:18
Show Gist options
  • Save tamarazuk/730e32cf2d81c498d9c2 to your computer and use it in GitHub Desktop.
Save tamarazuk/730e32cf2d81c498d9c2 to your computer and use it in GitHub Desktop.
Customer/Order XML Export: Adding a new merge variable for the order export file name.
/**
* Add support for %%payment_method%% merge variable to XML export file names
*
* @param string $post_replace_filename the post replace filename
* @param string $post_replace_filename the pre replace filename
* @param array $order_ids the order ids
* @return string
*/
function wc_xml_export_suite_file_name_payment_method( $post_replace_filename, $pre_replace_filename, $order_ids ) {
// define your variables here - they can be entered in the WooCommerce > XML Export Suite > Settings tab
$variables = array( '%%payment_method%%' );
$payment_methods = array();
foreach ( $order_ids as $order_id ) {
$order = wc_get_order( $order_id );
if ( $order ) {
$payment_methods[] = $order->payment_method_title;
}
}
// define the replacement for each of the variables in the same order
$replacement = array( implode( '-', $payment_methods ) );
// return the filename with the variables replaced
return str_replace( $variables, $replacement, $post_replace_filename );
}
add_filter( 'wc_customer_order_xml_export_suite_export_file_name', 'wc_xml_export_suite_file_name_payment_method', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment