WP CLI Scripts and WooCommerce

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.

Continue reading

Managing Fraud Orders in WooCommerce

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

How to Avoid Excess Meta with WooCommerce Subscriptions

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

Update the Modified Date in a WooCommerce Order

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.

$order = wc_get_order( 123 );
$order->set_date_modified( time() );
$order->save();

Launching an Extension in the WooCommerce Marketplace

I launched an extension in the WooCommerce Marketplace! It’s been three years since I came up with the initial idea and it’s exciting to see it being sold on WooCommerce.com.

For anyone interested in selling WooCommerce products, I wanted to share some thoughts on the process.

Coming Up With A Product

The extension idea originally came out of a client project. A company I worked with acquired a lot of their new customers through Facebook advertising, and they wanted a way to offer those new customers a big discount on their first purchase.

The first version of the extension took a couple days to build. It simply added a checkbox to the coupon editor for marking coupons as “new customer only” and validation on checkout. From that basic idea, I then started to add other restriction options I thought would be useful.

WooCommerce client work is great source of extension ideas because it requires solving a real need for a customer (and is something they’re willing to pay for).

To get the extension idea accepted to the WooCommerce Marketplace, I also had to prove that others wanted this functionality. Luckily, a number of people had also requested this on the WooCommerce idea board as well.

Continue reading

Example Cart Restrictions in WooCommerce

I’ve been working with a “Trial Product” in a WooCommerce store which needs to be the only item in the cart during checkout due to shipping requirements (and because it doesn’t make sense to order a trial if you’re also going to order the actual product).

To make this clear to the customer, I’ve restricted what can be added to the cart in specific situations:

1) If the “Trial Product” is already in the cart, additional products should not be added. WooCommerce will instead display a notice asking the customer to remove the “Trial Product” from their cart if they wish to add different products.

2) If products are already in the cart, and the customer attempts to add the “Trial Product”, a notice will display asking the customer to remove the other items from their cart first.

Continue reading

Automated WooCommerce Testing with Ghost Inspector

WooCommerce sites are made up of a complex set of integrated parts. There’s WordPress, WooCommerce itself, other third-party plugins, and a theme. Each of these components require frequent updates and has the potential to break critical functionality on your site. This is why it’s critical to have automated tests.

For a WooCommerce site I used to work with, we had a checklist of items we would manually run through after any major update:

  • Verify products on home page look correct and load
  • Test “Add to Cart” button
  • Test removing item from cart
  • Verify all product on /shop page look correct
  • Test complete checkout with Stripe for guest checkout
  • Test complete checkout with PayPal for guest checkout
  • Test complete checkout with Stripe with coupon for guest checkout
  • etc.

Needless to say, this took a lot of time. Thankfully, tests like this can all be automated using Ghost Inspector.

Continue reading

Subscription Toggle in WooCommerce

In WooCommerce subscription products and standard products can’t be combined. For example, if you’d like to offer customers the option to purchase coffee as a one-time sale or as a convenient monthly subscription, you’ll need to create two separate products on the backend (even though it’s essentially the same product and SKU).

If you’re SEO focused, this might be a concern in terms of duplicate content and splitting page rank. For customers, this also isn’t a great experience. If a customer lands on the one-time product page, they might not know about the subscription option (and vicea versa).

A better example of subscription user experience is Target. If a product offers a subscription option, there’s a radio button toggle with a discount clearly highlighted. Turns out, with a little work, this is also possible to do in WooCommerce. Continue reading