WooCommerce code snippet: convert the Order Notes field into an EU VAT ID field

The scenario: My WooCommerce store has no need for the Order Notes field. In fact, up until now I had it hidden on the checkout page. But what my site does need is an EU VAT ID field. The portion of my business that takes place in Europe is, so far, well below the VAT reporting threshold, but I am increasingly being asked by customers to provide an invoice containing their VAT ID.

Well, my site does already produce PDF invoices. But there was no way for customers to include their VAT ID on the invoice. Until now.

A simple code snippet converts the existing WooCommerce Order Notes field into an EU VAT ID field, including changing it from a <textarea> to an <input type="text"> field. Put this in your theme’s functions.php file, or wherever else is appropriate in your setup:

add_filter('woocommerce_checkout_fields', function($fields) {
    $fields['order']['order_comments'] = array_merge(
        $fields['order']['order_comments'],
        array(
            'class' => array('eu-only'),
            'label' => 'EU VAT ID',
            'type' => 'text',
        )
    );
    return $fields;
}, 10, 1);

That’s it. You can stop right here. But you may notice a line in there that seems unnecessary: 'class' => array('eu-only')

What’s that all about? Well, I’m using that with a bit of jQuery to enhance the functionality: only showing my new EU VAT ID field when the user’s selected Billing Country is an EU country.

Here’s a JavaScript function you can use to dynamically show/hide elements with an .eu-only CSS class, depending on a given passed-in value:

function showHideEUOnly(val) {
    var eu = ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'ES', 'SE', 'GB'];
    if (eu.indexOf(val) != -1) {
        jQuery('.eu-only').show();
    }
    else {
        jQuery('.eu-only').hide();
    }
}

I obtained the list of EU VAT-applicable countries here, and I decided to include 'GB' (the United Kingdom) in the list, despite… y’know, uh… Brexit, because I have the vague impression that UK customers may still be impacted by VAT policies. (Being a dumb American, I don’t know much about it. I think maybe the UK has its own VAT now? Anyway, suffice to say, you may want to modify your list of 2-digit country codes in the eu array, as applicable to your situation.)

This function isn’t going to do anything unless it’s called though, so let’s do that. Here’s a bit of jQuery that will call it both on the initial page load and any time the Billing Country field changes:

jQuery(function() {
    if (jQuery('body').hasClass('woocommerce-checkout')) {
        jQuery('select[name="billing_country"]').on('change', function() {
            showHideEUOnly(jQuery(this).val());
        });
        showHideEUOnly(jQuery('select[name="billing_country"]').val());
    }
});

Both of these JavaScript snippets can go in a script.js file in your theme, or wherever else is appropriate in your setup.

That’s the end of the story, but there’s more…

Incidentally, there’s more to my custom setup. I’ve significantly modified the layout of my checkout page. I’ve got WooCommerce configured for billing addresses only, with this setting in Shipping Options:

I then used CSS to hide everything else in the second column (including, up until now, the Order Notes field) and moved the product summary and payment information up into that space. Explaining all of that is outside the scope of this post, but one thing you may find useful is my CSS for hiding the “Additional Information” <h3> heading. This selector is a bit of overkill, but it works:

body.woocommerce-checkout .woocommerce > form.checkout .col2-set > .col-2 .woocommerce-additional-fields > h3:first-child { display: none; }

There’s context in my CSS file to justify all of that, but you should be able to accomplish the same with just this:

.woocommerce-additional-fields > h3 { display: none; }

On effective altruism, longtermism, crypto bro billionaires, and the boringness of maintenance

This morning I was reading a Vox article entitled How effective altruism let Sam Bankman-Fried happen, and if that title isn’t enough to scare you off, the first few paragraphs probably will be.

Of course, I am a glutton for punishment, especially when people in their third decade think they have solutions to all of the world’s problems. Not to be a crusty curmudgeon, even though as a “Gen X”er it seems to be my destiny. I just feel like you have to have first-hand memories of the 1980s for proper context on what’s happening today. Or maybe not, but you at least need to be even more cynical about the claimed promise of crypto than the author here. You know, cynical enough to not take the money in the first place.

The problem actually is longtermism

One section of the article begins with the subhead “The problem isn’t longtermism.” But I would argue that, in fact, it is the problem. Or rather, it’s one of a cluster of problems that all come out of the heads of people who think they are smarter than everyone else and somehow have The Answers that are beyond the grasp of mere mortals.

It’s the same mentality that lets a person make the choices (often building on past choices by their forbearers, the ones who allowed them to be “born on third base, thinking they’d hit a triple”) that lead to becoming a billionaire in the first place. It’s a status that can only be achieved on the backs of others.

But whether you’re a billionaire striver, an aspiring Mars colonist, just an ordinary “maker,” or a grandiose philosopher of the distant future, the common thread is that it’s more fun, more inspiring, to invent something — to inhabit a fresh, clean, newly-constructed mental space — than to do the messy, mundane, boring work of maintaining what we already have. Of cleaning up other people’s messes. Of learning how someone else’s invention works, because they’ve moved on to the Next Big Thing and now you’re the one charged with keeping the previous Next Big Thing up and running.

I get it. It’s the same for me, in many ways. I’m a “maker.” I work as a consultant, brought in to create new systems, that then get handed off to internal staff to keep running, while I move on to the next client. But I’m not claiming to solve all of the world’s problems; I’m just making something new that people ask me for when their old thing stops working.

OK, the problem actually is billionaires. Period.

It’s dangerous when the means to solve society’s big problems are concentrated in the hands of a small group of billionaires, and we are left to trust their vision for how that money should be used. These are the guys (and it’s pretty much always guys — bros, if you will) who get that thrill out of grandiose thinking, who don’t want to deal with the messy realities all around us. They don’t want to fix problems. They want to invent something, clean and shiny and new. Don’t clean up Earth; move to Mars. Don’t improve public transportation, distract us with ludicrous promises of tunnels and tubes, so we buy your fancy new cars instead. Don’t do the hard, complicated work to improve the actual lives of the billions of humans who are living in poverty today; concoct some imaginary future event that might kill billions of people, and invent a fancy new high-tech gizmo that will prevent that event from happening.

Later on, the article does get into a lot of the problems with big longtermist philosophy and silver spoon crypto bros who think they understand all of the world’s problems better than anyone who actually has any of those problems in their own lives.

But ultimately, for me, it all simply comes back to the idea that billionaires shouldn’t exist. And since they shouldn’t exist, they shouldn’t be making decisions about how to fund solutions to society’s problems.

On canceling my Minnesota Twins season tickets, and the nature of professional sports

I’ve had Twins season tickets since Target Field opened in 2010. Not a full-season package, mind you. I don’t see how anyone who works for a living has time for 80 baseball games a year. Or even 40. But I’m now in my 13th year of a 20-game package, and most years (minor inconveniences like pandemics aside), I’ve actually managed to make it to 16 or 17 of them.

This year I’ve had a lot going on, and have had to reschedule (ticket exchange is a nice new benefit in the past couple of years) or miss entirely over half of the games in my package. Combine that with increasing concession prices with limited options (especially for someone who doesn’t eat meat), few other season ticket holder perks I find interesting, and the perennial futility of this particular team, and each year it has been harder and harder for me to justify renewing.

Finally over the weekend, when I missed two games in three days due to more schedule conflicts — mixed with a dash of struggling to care about a team that is once again failing to live up to even modest expectations of success — I decided I was done with it, and I emailed my rep to say I want to cancel for next season.

Last night was my first game since canceling. And what a game it was! The Twins had just finished getting swept in a 4-game series by the division rival Cleveland Guardians, a series that knocked the Twins — who had dominated the division in the first half of the season — down to third place, and below .500 for the first time since April.

But they came roaring back in last night’s game against the lowly Kansas City Royals with three home runs, and by the middle of the fifth inning, the crowd was beginning to notice that Joe Ryan also had a — shhh! don’t say it out loud! — no-hitter going.

By the end of the seventh inning, he still had a no-hitter going, and the excitement in the stadium was palpable. We might be witnessing Twins history… their first no-hitter in over a decade! But Kansas City was not making it easy. Pitch after pitch after pitch was fouled off, and by the time the last out was recorded in the seventh, Ryan had already thrown 106 pitches.

Twins manager Rocco Baldelli is a serious analytics guy. The whole game is numbers to him, to the detriment of fan excitement or even a moment of unpredictability. And one of the biggest numbers is that magic “100” pitch count. Once your starter hits 100 pitches, he’s done, no matter what. So I knew there was no way he was going to let Ryan come back out in the eighth, no matter how much of a case he might be pleading in the dugout.

So it was… Jovani Moran kept the no-hitter going through the eighth, but with one out in the ninth, he walked two batters, then gave up a double. The no-hitter was gone, as was the shutout. In the end, the Twins won, 6 to 3, but it felt worse than a loss.

I woke up this morning still thinking about the game, and getting philosophical about it, and about my waning enthusiasm for this team I have loved (at least, in fits and starts) since I was in middle school and they won their first World Series.

What is the purpose of professional sports? They are entertainment. That is their only purpose.

Fans pay a great deal of money to be entertained, and the people who comprise the “sports industrial complex” — professional athletes, coaches, staffs, broadcasters, etc. — make their very comfortable livings from the money those fans pay.

But guys like Rocco seem to think sports exist for some other reason unto themselves. That they matter in some way apart from the fans.

They do not.

If you are not making the game entertaining for the fans, you are failing at your job. And if you allow the game to be entertaining for the first 7/9, and then make a decision that ruins the remaining 2/9, you’re still failing… even if you win.

But here’s the thing: even if sports did exist for a reason unto themselves, Rocco’s approach is not going to lead to success. A conservative, risk-averse, analytics-obsessed approach can only take you so far. Baseball needs an element of risk, of surprise. Bold, unexpected, sometimes irrational decisions are what make a good team great, or at least make an average team fun to watch.

The best the Twins will ever be with Rocco’s approach is “good.” Yes they touched greatness in 2019, with their first 100+ win season since 1965, and setting an MLB record for team home runs in a season, but something strange was going on in the entire MLB that season with juiced balls or something. Then, of course, that team that was so dominant in the regular season still instantly fell apart in the postseason, because that’s what the Twins do. And that’s never going to show up in your analytics.

When easier isn’t (or: Why I typically avoid using managed hosting like Flywheel)

I’ve been building websites since there was no alternative to the command line when it came to configuring web servers. Well… unless you were using a Mac as a server, which didn’t have a command line back then. (And, yes, it could be done. The ISP I started working at in 1996 ran entirely on Macs, except for one Sun SPARCstation we were using as a DNS server.)

I still prefer the command line, and when I have a choice, I build web servers on a VPS from a vanilla install of Ubuntu Linux. I used to use Digital Ocean, but now Linode is my preferred host.

But if a client already has their site hosted somewhere else, I’ll work with what they’ve got. I take the “if it ain’t broke, don’t fix it” approach. As long as the client doesn’t have major issues with their current hosting provider, it’s usually much easier to keep things where they are than to move their site somewhere else.

Even if that current hosting provider offers, ah-hem, “Managed WordPress Hosting.” I cringe at that phrase, because what it really means is that I have less control to set things up the way I like.

The way I like things isn’t the way they have to be, of course, but it would be nice if their easy-to-use tools actually made things easier to use.

Let’s take rewrites, for instance. Editing the .htaccess file can be a dark art, but once you know the basics and can handle regular expressions, it’s not that difficult.

Launching a new site that’s replacing an existing one almost always involves setting up rewrites. You want to make sure URLs from the old site, especially ones that people might have bookmarked or, even more importantly, Google might have indexed, automatically shunt users over to the corresponding URL of the new site.

Often a client will give me a fairly large spreadsheet of URLs to map. Setting this up in a text file, especially if you use an editor with good find-and-replace, is a snap.

Flywheel offers SFTP access to your site, and it even contains an .htaccess file

The things I make don’t exist

Like most “creatives,” I have an impulse — maybe a compulsion — to make things. I’ve often reflected on the nature of this impulse, wondering why I simply feel in my bones that I need to do this.

I think in some ways it’s about mortality. Our existence is temporary and fleeting. We want to leave a mark on the world. Something that says “I was here.” The impulse to leave a mark often takes a dark turn, but even when it doesn’t, the fragility of our modern world calls into question the extreme vanity of thinking that somehow your existence matters enough that you need to construct monuments to yourself.

But in my case, there’s an even weirder element to the impulse. Nothing I make exists. That is, it doesn’t exist as physical objects. The closest I come, I guess, is if I print out a piece of sheet music I’ve composed. But unlike a painter, a sculptor, a knitter, a builder… the things I make are even more fleeting and ethereal than my own existence.

Sound waves in the air. Momentary flashes of pixels on a screen. The flow of electrons inside computer chips. None of it is real outside of the moments someone experiences it. And worse, most of it is dependent upon the right hardware and software continuing to operate to manifest those moments again in the future. And all of it depends on electricity.

Intermittently through the years I have run an online shop where I sell merchandise featuring my designs, all created on a computer. I just launched a new one. But I don’t make the products. I certainly am not stitching together the t-shirts or firing the coffee mugs in a kiln or… doing whatever it takes to physically create a sticker. I’m not buying the blank merchandise and printing my designs on it. I’m not even warehousing stock. Everything I sell is print-on-demand, and the “photos” of the merchandise on the site are just composites created by the fulfillment vendor’s software.

That gave me the idea for this t-shirt. It doesn’t exist. And as long as no one ever orders one, it will stay that way.