PDF Ink is a favorite among composers and sheet music sellers because it allows licensing information to be added anywhere on the page, right up to and even over the page margins.
One of our customers, Guillaume, is using the Checkout Field Editor for WooCommerce plugin to enhance a checkout form with a field requiring buyers to enter their ensemble name, like “University Concert Choir.” Guillaume would like to have a Magic Tag called [ENSEMBLE] to use for printing the ensemble name on purchased PDF files. Let’s walk through how to set this up so the ensemble name then appears stamped on the PDF, clearly marking it for that specific group.
Side note: The Checkout Field Editor plugin that Guillaume uses is user-friendly and stores data in a way that’s compatible with other similar plugins. This means you can possibly apply these steps even if you’re using a different Field Editor. (The Advanced Custom Fields plugin would be handled differently.)
Guillaume’s extra checkout information gets added to the completed WooCommerce order, saved in the WordPress database. So when we create our custom “Magic Tag” for PDF Ink, we can easily access the ensemble details using the order number. Simple, right? It really is!
Start by activating the Checkout Field Editor plugin to your WordPress and heading to its settings. At the bottom are our settings for adding a required Ensemble field to the WooCommerce checkout form:

The field will say, “Scores will be licensed to:” prompting the customer to enter their ensemble name. It’s important to make the field required if you plan to stamp/watermark with it, because if the field is empty, so is the custom [ENSEMBLE] part of your watermark. If you are very serious about it, you might add some validation to the form field, to make sure people don’t type something like “???” or “whatever” or “nonyabidness” in the field (which happens, but maybe not so often in the sheet music industry). Adding validation is a separate project, though.
The customer checks out and fills in your custom field with their information. That info is stored in the WordPress database WooCommerce Orders Meta table (usually “wp_wc_orders_meta” unless the table prefix has been changed), under the order number as “order_id”. In our case the meta_key for that information is licensed_ensemble, and the meta_value might be something like, “Interstate Children’s Chorus”. We’ll use this understanding now in some PHP code:
function my_ensemble_magic_tag( $content, $key, $order_id, $product_id ) {
// First we need to get the order object from the order id
// you can get a lot of info from the order object ( $order in this case)
$order = wc_get_order( $order_id );
// Let's fetch meta value we want, which is under the 'licensed_ensemble' meta key.
$ensemble_name = $order->get_meta( 'licensed_ensemble' );
// If there isn't an ensemble name for some reason, we stop. [ENSEMBLE] tag translates to nothing (is blank).
if ( ! $ensemble_name || $ensemble_name === '' ) {
return $content;
}
// When we find [ENSEMBLE] in a watermark, replace it with the ensemble name
$content = preg_replace( '/\[ENSEMBLE\]/', $ensemble_name, $content );
// Send the filtered content back
return $content;
}
add_filter( 'pdfink_filter_placement_content', 'my_ensemble_magic_tag', 10, 4 );
Add this PHP code to the bottom of your child theme functions.php file or by using the “Code Snippets” WP plugin (front and backend), and you can now use the new [ENSEMBLE] magic tag.

In a similar way, using the Checkout Field Editor for WooCommerce plugin, many other custom PDF Ink magic tags could be created to dynamically stamp just about any custom content on your PDF files. Basically, if you are collecting information from your WooCommerce customers, then you can stamp it on their files.
Thank you to Guillaume for sponsoring this PHP snippet and may it help many other composers. Ensemble does mean “together” in French, after all!