Clearly I need to think ahead a bit more. Over the last few weeks I’ve had a ton of sales, and I’m preparing everything to be ready to send them out as soon as I receive them from the supplier. Unfortunately our supplier contact me and advised there’s a few days delay on one product and about 10 days delay on another.

So I now need to mass mail people telling them.

I did look at using elasticemail to mass mail, but there’s a whole thing in their templates gearing towards marketing mails and opt out information. This isn’t a marketing mail it’s part of the transaction, I could live with giving it some opt out links. but what I really need is to be able to mail merge the order information into the mail.

So I quickly gave up on using elastcmail’s campaign function. I still use them as my mail relay and they’ve been very good, and support has been top notch for the few questions I’ve had.

Anyway, I thought back to the code for adding bulk actions and remembered there was an email function. So I checked out the code again, and yep it should be able to do what I need.

I decided to do things a little differently though.

First I create 2 new order status using JetPack (you can code this but it’s easier to just type and submit in jetpack) :
stock-emailed
stock-email-fail

I’m going to be bulk assigning every order I want emailed to stock-email, anything that fails (wp-mail does fail) will go to stock-email-fail. This is the bit that wasn’t in the orginal code.

I also want to pass the orderid and name into the mail function. I could just have the mail function go get them, but it already queries the email address in the change_order_status function so I may as well keep it there.

I haven’t include the full email above, just a snip so you can see where I put the orderid and name. The actual template I’ve used is one off woocommerce itself to keep the look of the emails the same as an order progress.

To get the mails flowing just select a bunch of orders and bulk change them to ‘Mark as Awaiting Stock Emailed’. This happily looped through 250 at a time on my system. After doing over 3,000 I only had 14 moved automatically to the failed status, and rerunning them didn’t cause any problems.

The one issue I did run into was the name of the failed status, originally I had it set as stock-emailed-fail. But there’s a limit on the number of characters you can use and it came into the system as stock-emailed-fai. I managed to loose 3 orders in the first test batch, as they were now assigned a status that didn’t exist. So I had to find them in the database and set them to the proper status. If you keep your slugs short, you shouldn’t see this issue. but make sure you also type the exactly the same in the code as they appear in jetpack.

I take no responsibility for any lost orders as a result of using this code.

A few months back I added some new order statuses in WooCommerce, then changed the code to be able to use these from the bulk actions menu. I then added them into the dashboard so I could get a quick overview of what I needed to do each day.

This was just a quick (maybe not so quick) edit of the admin files. A while later I update WooCommerce and bang goes my edits (yes I can hear everyone shouting ‘should have made a child theme’). I did actually have a child theme running, but it was just a quick dirty way of getting it done at the time. I needed to concentrate on orders.

Anyway back to now, we’ve had a few thousand orders in a short space of time and once again I need my custom statuses from the bulk menu. This time I decided to do it right.

After searching and searching, I couldn’t find anyone saying how to add to the bulk menu, plenty of stuff about adding a status but you have to then edit each order to use it. Knowing I’ve done it before and didn’t take half the day doing so I kept searching. Eventually I found http://www.niepes.com/web/how-to-create-a-custom-order-status-in-woocommerce/ and this is exactly what I needed.

Well sort of. I didn’t want the email side of it and actually wanted to add a few customs (2 atm) . So I changed the code a little.

Find below the code I have now added to functions.php (note I already created the custom statuses of ‘printing’ and ‘stock’ using WooCommerce Jetpack.

I started this bog with the idea of keeping notes of things I may need to refer back to. Tonight I’ve spent 30 mins searching the entries for LDAP authentication on the PI. I do LDAP Auth on all my servers against 2 LDAP servers, and I’m sure I posted somewhere what I did to configure the PI’s to auth against LDAP but I just can’t find it.

What it has highlight though is 1) I don’t post nearly enough of what I do, and when I do it’s normally after I’ve done it and then write it up from memory. 2) The blog design just ins’t very user friendly.

So I’m going to try to write things up a bit more often as I’m doing them and tonight I’m going to look at some better designs. I’ve been installing wordpress quite a bit recently and it just seems to have themes and a better layout, so I’d like to get a similar design running on this blog. I would just run the blog on my own server, but I think there’s a good chance moving my blog will screw up any references to blogspot. Maybe something to look at though when I’m bored.