tamarazuk
4/2/2015 - 10:15 PM

Customer/Order XML Export: Adding a new merge variable for the order export file name.

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 );