Personalise PDF Vouchers on checkout

When using WooCommerce PDF Product Vouchers, the default flow allows a visitor to enter a personalised message on the product page.

If you want the visitor to personalise the voucher during checkout, this presents a problem since the PDF Voucher plugin doesn’t have this feature.

Our solution was to add a custom checkout field using the Custom checkout fields plugin, which we named billing_extra.

This field made it possible for visitors to add a custom message on checkout, but it still didn’t appear on the PDF voucher.

Luckily, the creators of WooCommerce PDF Vouchers provide a filter that we could hook into, wc_pdf_product_vouchers_get_message.

Billing_extra is added to the order as post_meta so we retrieve it by using the order_id.

And finally, our hook:

add_filter( 'wc_pdf_product_vouchers_get_message', 'my_prefix_get_message', 10, 2 );

function my_prefix_get_message( $message, $voucher_object) {

    return get_post_meta( $voucher_object->get_order()->id, 'billing_extra', true );