Pull Order Data from WooCommerce and Stamp Your PDFs – with VAT Info

Cartoon graphic of EU flag with VAT written on it.

If you run a WooCommerce shop that sells digital goodies like e‑books, manuals, or templates in PDF format, you already know how satisfying it is to watch a customer click “Download.” Imagine taking that moment a step further: each PDF leaves the checkout with a tiny, personalized imprint—perhaps their name and email, order number, copyright notice, or timestamp—right on (or hidden inside) the file. Not only does this add a professional touch, it helps you prove ownership, deter piracy, and keep tidy records.

PDF Ink allows for adding quite a bit of customer data easily using magic tags1. There is no magic tag for VAT, but using a little code, we can and add a EU VAT (Value Added Tax) ID magic tag. When our code is installed, the magic tag[VAT] will be replace by an actual customer VAT when watermarked on a PDF or EPUB file.

Below is a step‑by‑step walkthrough of how to harvest the data you need from the WooCommerce $order object, and feed it to PDF Ink for stamping on your PDF files.

Grab the Order Object via Hook

When a PDF is clicked for download, WooCommerce fires the woocommerce_download_product_filepath filter hook. PDF Ink hooks into that to maybe alter a file before it is delivered. During that process, PDF Ink allows filtering of placement content using the pdfink_filter_placement_content filter hook. The hook provides us the ability to alter the placement text content, choose which placement to alter if desired, and then it provides us with powerful variables: order ID and product ID.

Fetch the $order instance, and you’ll have instant access to everything the customer supplied at checkout—including any VAT‑ID collected by a plugin like WooCommerce EU VAT Number.

add_filter( 'pdfink_filter_placement_content', 'filter_placement_to_add_vat', 10, 4 );

function filter_placement_to_add_vat( $content, $key, $order_id, $product_id ) {
    // Since the $order object can provide us a lot of data, we will start by
    // getting the $order object from the $order_id
    $order = wc_get_order( $order_id );

    // If we know we've used our [VAT] shortcode only in Placement #2,
    // we can speed up this code by only performing on #2. (Indexing starts at 0.)
    if ( $key !== 1 ) {
        return $content;
    }

    // Pull the VAT from the order object
    $vat_id = $order->get_meta( '_billing_vat_number' );

    if ( empty( $vat_id ) ) {
        $vat_id = $order->get_meta( '_vat_number' );
    }

    // For the Germanized plugin, you'd probably use this instead:
    if ( method_exists( $order, 'get_billing_vat_id' ) ) {
        $vat_id = $order->get_billing_vat_id();
    }

    // If there isn't a VAT, we give up and return the content as it was
    if ( empty( $vat_id ) ) {
        error_log( 'No VAT found for this order.' );
        return $content;
    }

    // remove . - / from VAT, keep it numbers only
    $vat_id = str_replace( [ '.', '-', '/' ], '', $vat_id );

    // When we find our custom magic tag [VAT] in a watermark, replace it with the VAT value
    if ( ! empty( $vat_id ) ) {
        $content = preg_replace( '/[VAT]/', $vat_id, $content );
    } else {
        error_log( 'VAT became an empty string or 0 after .-/ characters were removed.' );
    }
    return $content;

}

Visible or Invisible Stamps with PDF Ink

PDF Ink offers straightforward ways to embed textual information:

  • Visible watermark – a faint banner or footer that readers can see. Great for branding (“© YourShop 2026”) or for reminding buyers that the file is licensed. This can be anywhere on the page and it can be repeated on the page. It can be an image.
  • Invisible watermark – the watermark opacity can be set to zero and it can be hidden on the page in very small font.
  • Invisible metadata – If you are using SetaPDF-Stamper (a paid enhancement for PDF Ink) you can hide fields stored inside the PDF’s XMP packet. Perfect for forensic tracking (order number, VATIN) without cluttering the layout.

With this in place, every time a buyer completes checkout, WooCommerce momentarily hands the original PDF to PDF Ink, which tacks on the data you selected—either as a subtle watermark or maybe as hidden metadata. The customer receives a fresh, uniquely‑marked file, and you gain a reliable audit trail.

The Perks of Personalized PDFs

  • Proof of purchase – If a customer claims they never bought the file, you can open the PDF and read the embedded order number, date, and even the VAT‑ID that matches your records.
  • Deterrence – Knowing each copy carries a unique signature discourages casual sharing
  • Compliance – Certain EU regulations (e.g., invoicing requirements) expect the VAT‑ID to appear on the document itself. Embedding it automatically keeps you on the right side of the law.
  • Brand polish – A tasteful watermark (“© YourShop 2026”) reinforces professionalism and protects intellectual property.

When to Hit Pause – Legal & Privacy Pitfalls

While stamping sounds wonderful, there are scenarios where you should think twice:

SituationWhy it mattersSuggested approach
GDPR‑covered customers (EU residents)Storing personal identifiers (VAT‑ID, email) inside a file that might travel beyond your control could be considered “processing” personal data.Ensure you have explicit consent to embed that data, or limit yourself to non‑identifying info (order number, timestamp).
Highly regulated industries (medical, financial)Some jurisdictions forbid embedding personal IDs in documents that could be shared publicly.Use invisible metadata only for internal tracking, and keep the visible watermark free of personal data.
US‑centric salesAmerican buyers may be unfamiliar with VAT‑IDs; showing them could cause confusion or raise privacy concerns.Detect the buyer’s locale and omit the VAT‑ID field for non‑EU customers.
Third‑party distribution (e.g., resellers)Resellers may need a clean copy without your internal stamps.Offer two download links: a “customer copy” (stamped) and a “partner copy” (plain).

A quick rule of thumb: If the data you’re embedding could identify an individual, double‑check that you have a lawful basis to do so (consent, contractual necessity, or legitimate interest). When in doubt, stick to order‑level identifiers that aren’t personally sensitive.

Your New PDF Superpower

By tapping into WooCommerce’s $order object, pulling stored data fields (like VAT) and feeding them to PDF Ink, you can watermark every PDF with that unique, identifying data. The result is a smoother audit trail, happier customers who see a polished, branded file, and a modest barrier against unauthorized sharing.

Give it a try, purchase PDF Ink, test with a few orders, and watch your PDFs wear their new badges of authenticity with pride. Happy stamping!

  1. VAT isn’t a built-in feature of PDF Ink because there are several different plugins collecting VAT data and all store the data differently. Besides, nobody ever asked. ↩︎