Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save conschneider/0bf13e10b84888eccfc27ac3effc30d3 to your computer and use it in GitHub Desktop.
Save conschneider/0bf13e10b84888eccfc27ac3effc30d3 to your computer and use it in GitHub Desktop.
Change WooCommerce PDF Voucher string to custom name
<?php //only copy if needed
//filter documented at: https://docs.woocommerce.com/document/woocommerce-pdf-product-vouchers-developer-documentation/#wc_pdf_product_vouchers_voucher_filename
add_filter('wc_pdf_product_vouchers_voucher_filename', 'cs_my_own_filename');
function cs_my_own_filename ($filename) {
// This is how the variable is defined: $filename = 'voucher-' . sanitize_file_name( $this->get_voucher_number() ) . '.' . $type;
// Note: $type may be defined as string. Default $type = 'pdf';
// Note: Do not use this filter to change the number. There are other filters for that.
// Change string 'voucher' in filename to 'Gutschein'
$myname = str_replace('voucher', 'Gutschein', $filename);
$filename = $myname;
return $filename;
// Outputs the following Filename: Gutschein[voucher number].pdf
}
@hussong
Copy link

hussong commented Mar 13, 2021

Love this, thank you!

@conschneider
Copy link
Author

Love this, thank you!

You are welcome!

@MarkKbrook
Copy link

Do I need to create an new file for this and where in my Child-Theme I have to put it in? Thank you.

@conschneider
Copy link
Author

Hi @MarkKbrook

You can put this in the functions.php of your child theme. There is no need to create a file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment