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; }

ST:TNG Treadmill Review #24: The Defector

The Defector
Season 3 Episode 10
Original airdate: January 1, 1990

Netflix Synopsis

When a Romulan officer defects to the Federation and warns of an impending invasion, Capt. Picard struggles to decide if he is to be believed.

My Brief Review

Welcome to the 1990s!

These Romulan episodes are almost always good. The Romulans are probably my favorite “enemy” alien species in Star Trek. Their ancestral connection to Vulcan, and the extreme contrast between their cultures, is a fascinating contrast. Beyond that, the Romulan characters are always pretty well written and acted. That’s definitely the case here.

James Sloyan (who I recognized in Romulan makeup but could not identify — he’s been in a ton of stuff but I know him best from his recurring character on Murder, She Wrote, as well as from the movie Xanadu) is great as the defector, Admiral Jarok, and we have the excellent Andreas Katsulas back, after just a few episodes (which his character even notes) as Tomalak.

Memorable Moment

The episode begins on the Holodeck, with Data acting out a scene from Shakespeare’s Henry V, and, if you look closely, you’ll notice that one of the holographic commoners is in fact Patrick Stewart in heavy makeup. Picard is watching the scene from a distance and coaching Data on his acting.

Crew Rando

Wes isn’t in this episode, so I was thinking perhaps Crewman Martinez would finally get some more screen time! Of course, I need to pay attention to my rank insignia pips. Crewmen don’t have any. The rando who’s at the helm throughout the episode is an ensign (and of course, a crewman wouldn’t be at the helm anyway). Unfortunately, the ensign isn’t even given a name! IMDb just lists him, uncredited, as “Operations Division Officer.”

Distance Rating: 5K

IMDb score: 8.5/10

Classic albums I belatedly “discovered” in 2012

I have, with some friends and acquaintances, cultivated the notion that I’m some kind of walking encyclopedia of music, especially that of the 1970s. But in reality there is so much music out there that I’ve never heard or just never really given a chance, even things by bands I really like. For instance, this year I finally heard Pink Floyd’s Obscured by Clouds for the first time. It was the album they recorded just prior to their legendary breakthrough Dark Side of the Moon, and it’s been on heavy rotation in the studio for the past few months.

That got me thinking: every year I compile my list of the top 5 new albums of the year, but I never reflect on the “new to me” music that I’ve only just gotten into this year. I’m not going to bother with a review of every album, but here’s a list of all of the new music I added to my library in 2012 that wasn’t released in 2012. Some of it is from the past couple of years; some of it is older than I am.

For extra fun, the list is presented in the order I added these albums to my iTunes library. I also bought a few greatest hits albums but I’m leaving them out, along with — of course — new remastered versions of albums I already owned.

  • Weather Report: Black Market (1976)
  • Antonio Carlos Jobim: Tide (1970)
  • Washed Out: Within and Without (2011)
  • Boards of Canada: Music Has the Right to Children (1998)
  • Washed Out: Life of Leisure (2010)
  • Hüsker Dü: Zen Arcade (1984)
  • Sufjan Stevens: Illinoise (2005)
  • Boards of Canada: Hi Scores (1996)
  • Boards of Canada: Trans Canada Highway (2006)
  • Billy Joel: 52nd Street (1978)
  • The Alan Parsons Project: I Robot (1977)
  • The Darcys: The Darcys (2011)
  • The Beach Boys: Concert (1964)
  • The Beach Boys: Summer Days (And Summer Nights!!) (1965)
  • The Beach Boys: Today (1965)
  • The Beach Boys: Live in London (1968)
  • Van Halen: Women and Children First (1980)
  • Bob Dylan: Nashville Skyline (1969)
  • Trombone Shorty: Backatown (2010)
  • Boz Scaggs: Silk Degrees (1976)
  • Def Leppard: Pyromania (1983)
  • Gong: Flying Teapot – Radio Gnome Invisible, Pt. 1 (1973)
  • The Sea and Cake: Car Alarm (2008)
  • The Mothers of Invention: Freak Out! (1966)
  • Frank Zappa: Hot Rats (1969)
  • Pink Floyd: Obscured by Clouds (1972)
  • Com Truise: Fairlight (2011)
  • Com Truise: Galactic Melt (2011)
  • Röyksopp: Senior (2010)
  • Röyksopp: Junior (2009)
  • Tame Impala: InnerSpeaker (2010)
  • Com Truise: Cyanide Sisters (2011)
  • Queen: The Game (1980)
  • Emerson Lake and Palmer: Live at the Mar y Sol Festival (1972)
  • Peter Gabriel: So (1986) [Seriously! OK, I did already own it on vinyl.]

Now I don’t feel like such a dork for my “You have died of dysentery” t-shirt

oregontrailshirtYes, it’s true. My nostalgic love of Oregon Trail extends to, occasionally, wearing a shirt featuring the green, pixilated image of an ox team and covered wagon, bearing the message “You have died of dysentery.” If you don’t get the reference, you might as well die of dysentery, because I have no use for you. (Of course, you don’t need to get the reference if you’re reading this, because I just told you.)

OK, that’s a bit of an exaggeration. But one thing is clear: as much as I love Oregon Trail, I’m nowhere near as passionate about it as Michael Nelson Price. Sure, it’s a joke, but you have to know the game inside and out to write an article like the one he did for McSweeney’s.

RPM 2009 is coming…

I’m getting fired up for RPM 2009. This will be my second year participating, and once again I’ve got my concept all ready to go.

Recording (and, ideally, composition) is not to begin before the clock strikes midnight on February 1, so I’ve been devoting my attention to designing my cover art. At this point I have the front cover ready to go (pending the inevitable tinkering between now and February 28). Here it is!

Anagrammatic Pseudonyms cover

Bonus points for anyone who knows what city’s transit system this design is patterned after. And extra double secret points for anyone who can correctly determine why I chose the Interstate numbers that I did. (Welcome, road geeks! And yes, I know there’s no logical reason for an I-176 spur off of I-99. No points for that.)