So maybe you accidentally deleted 600,000 customer records and associated usermeta from a WordPress site. Or maybe I did. Regardless, it’s a problem and they now need to be restored.
Thankfully, there’s a backup (boy howdy, you better hope so). Our site is hosted with WP Engine, so we restored a snapshot from before the accidental deletion to a new environment.
We hadn’t deleted all the user records, just a subset. But the easiest way to restore them from the backup was to export the all the users and usermeta within a specific range- but then only restore the ones that were missing. We did this using WP CLI. Continue reading →
If you manage a WooCommerce store, you’ll like need to bulk update or modify a large number of orders, subscriptions, products or customer records at some point. Writing a WP CLI script can be a quick and easy way to do this.
In this video I show how to export products into a CSV using WP CLI and the command wp eval-file, but the general concepts can be used to loop over any resource you may want to export, modify or delete.
One morning I woke up to find 20,000 new fraudulent orders on a WooCommerce site I manage. The vast majority of them were in failed status, but a few had successfully completed. We quickly determined this was a card testing attack, where a fraudster was using an automated system to iterate through a huge amount of stolen credit card numbers to check out on our site and determine which ones were still valid.
The biggest concern with this type of attack is that your credit card processor may stop processing payments from your site altogether due to fraud concerns, which means the business is dead until you can find a new payment processor.
As soon as we noticed the fraud, we alerted our payment processor and let them know we were taking steps to stop the attack and refund the fraudulent orders- which I think was helpful for keeping our account in good status. Continue reading →
We had an odd situation where disk space was getting swallowed up on a Digital Ocean server running Laravel. The issue started happening after an upgrade from Laravel 7 to Laravel 8 (though it could have been there before unnoticed). The database size had been growing, so my first though was just to resize the droplet. But when an additional 100GB was eaten up over the weekend I realized there must be something else going on.
It turned out we had deleted log files that were still being kept open by a system process, and therefore could not be fully deleted, but were also continuing to grow:
Orders in WooCommerce create a lot data in the postmeta table. There’s the standard WooCommerce fields (like _order_key, _cart_hash, _billing_first_name, etc.), but payment gateway plugins, marketing integrations, and other WooCommerce plugins also generate their own metadata. It’s not unusual to see more than 60 rows of metadata for each order.
I recommend the Post Meta Inspector to easily view all the metadata on any order or post. You may be surprised how much there is!
If you run subscriptions on your site and generate a lot of renewals, WooCommerce Subscriptions may be creating a lot of unneeded metadata due to how subscriptions and renewal orders are generated. This can cause your database to grow really quickly. Continue reading →
If you run a script to update order properties in WooCommerce, you may want to update the “post_modified” date along with the other updates. Many third-party integrations rely on the post_modified date to sync any order changes or updates.
Here’s how you can easily update the modified date (assuming you have the order object):
$order->set_date_modified( time() );
Here’s a full example which fetches the order, updates the date, and saves the order.
Having a nice GUI to make direct database queries can be really helpful when working with a complex WordPress site. TablePlus is the best one one I’ve found for the Mac.
Using TablePlus with WP Engine
Connecting to a local database and most remote databases should be pretty straightforward, but there’s a few extra steps if the database is hosted with WP Engine.
WP Engine has remote database access instructions here. Make sure to get your IP address whitelisted, include the cert, and get the ports right. Here’s a screenshot of what the settings should look like.