Goal: Become master of WordPress.
Mission #1: Write my first plugin for WordPress.

July has come and gone in the blink of an eye and with it the entire Nexus team has been working hard on a brand new wonderful website for the even more wonderful Steph of SLS Fitness in Ayrshire! This new website will allow Steph full control over her business online; giving potential clients loads of exciting information about what classes she offers (ever wanted to Rave yourself slim? We know we want to with Steph’s Raving Fit class!), information about Steph, the very exciting SLS Hub which will offer information exclusive to members of SLS, and the ability to book classes online.
Now, the ability to book classes online required a little bit of customisation and development to the default WooCommerce system in order for it to work perfectly to Steph’s requirements. By default, WooCommerce assumes that you’re selling a physical product and not using it as a booking system, and so it asks the customer for a whole range of address details etc, which aren’t necessary for this website. So, the Nexus team thought, what better an opportunity than for Susanna to try and write a simple little plugin that will give us the option to remove these fields if we need to?!
So, with my goal of becoming a WordPress master in mind, I put on my thinking cap and went straight to the obvious first step of any development work here at Nexus: pick Gordon’s brain! I decided it would be good to have a little look at some of the small plugins that Gordon’s wrote for Nexus’s WordPress setup lately to see what I’d need to include and discovered that I needed three things: the file with my code to exclude the fields we want to get rid of, a change log which details the changes you make to the plugin over time, and a read me file which just gives a bit of info about the plugin.
First things first, I saved a copy of the change log and the read me files that Gordon had previously used and edited them to be appropriate for our new plugin, giving information about what the plugin’s used for (excluding unnecessary fields) and the author (me!). So that’s 2/3 of my mission done already… now for the hard bit.
Or the not so hard bit, as it turns out. Isn’t Google just the best thing? A quick search on how to exclude the fields within WooCommerce found me this little nifty bit of code:

add_filter( ‘woocommerce_checkout_fields’ , ‘custom_override_checkout_fields’ );
function custom_override_checkout_fields( $fields ) {
unset($fields

[‘billing’][‘billing_address_1’]);
unset($fields[‘billing’][‘billing_address_2’]);
unset($fields[‘billing’][‘billing_city’]);
unset($fields[‘billing’][‘billing_postcode’]);
unset($fields[‘billing’][‘billing_country’]);
unset($fields[‘billing’][‘billing_state’]);
unset($fields[‘billing’][‘billing_phone’]);
unset($fields[‘billing’][‘billing_address_2’]);
unset($fields[‘billing’][‘billing_postcode’]);
unset($fields[‘billing’][‘billing_city’]);
return $fields;
}

It doesn’t look like much, but basically this is exactly what I was looking for! All this code does is tell WooCommerce to exclude the fields (that’s the “unset fields” bit) that you specify in the square brackets. So I pasted this in, made sure it was only excluding the ones we want it to exclude, and saved!
Activate the plugin, a quick wee refresh of the website, and… Success! The website now only shows the user the fields that we want it to show, none of this confusing address nonsense for a class booking form. It may not have been much, but it’s one step closer to being a WordPress master, and one more website working exactly the way we want it to – so I’m happy.