WC Gift Cards
A WooCommerce gift card plugin for a tailor's webshop: custom purchase flow, custom emails, and a PDF the buyer prints at home.
Same client as my suit configurator, a Danish tailoring shop. This time they wanted gift cards. There are plugins for that, but they wanted a custom pipeline: custom PDF to print, custom email, everything custom.
So it's its own WooCommerce plugin, with its own database tables instead of WooCommerce coupons.
Buying one
The buyer picks an amount, picks one of three designs, and writes a personal message. The preview card on the right updates as they type. They choose who gets the card (the recipient, themselves, or both), and they can schedule the email for a later date.
After checkout the recipient gets an email with the card, and the buyer gets a PDF to print at home and give as a present.

The PDF, emoji included
The PDF is the part I'm proudest of. It's built from an HTML template with mPDF, with custom fonts bundled in the plugin.
The annoying part was emoji. People write emoji in the personal message, and mPDF can't draw colour emoji, so they came out as empty boxes. Now the plugin finds every emoji in the card before rendering and swaps it for an image:
1if (preg_match_all($emoji_pattern, $html, $matches)) {2 $found_emojis = array_unique($matches[0]);34 foreach ($found_emojis as $emoji) {5 // Extract font size from surrounding context for dynamic sizing6 $font_size = $this->extract_font_size_for_emoji($html, $emoji);7 $emoji_replacements[$emoji] = $this->get_emoji_png($emoji, $font_size);8 }9}
The pattern catches flags first, since a flag is two characters that only mean something together. Each emoji is fetched from WordPress's own emoji set and sized to match the text around it, so an emoji in the 32 px heading comes out bigger than one in the message. Generated PDFs are cleaned up by a daily cron job.

The shop's host ran PHP 7.4 and had no Composer, so mPDF couldn't be installed the normal way. The plugin ships without a vendor folder and downloads a ready-made 1.8 MB bundle on demand instead, with a progress bar in the admin. I put the bundle on Google Drive, since it was the quickest place to host a file the server could download. If mPDF still isn't there, the plugin falls back to a printable HTML version.
Using one
In the cart you can stack several gift cards on one order and use just part of a balance. Each card shows what it covers and what's left, like "Bruger: 100 kr • Tilbage efter køb: 400 kr" (100 kr used, 400 kr left after the purchase). The order summary lists every code with its own line.
When the order goes through, the balance update runs in a database transaction and locks each card's row with SELECT ... FOR UPDATE, so the same card can't be spent twice by two orders at once. Balance checks and code entry are rate-limited too, so nobody can guess codes by brute force.