Deleting scheduled actions

From time-to-time, you may need to bulk delete a set of actions scheduled with Action Scheduler.

This can be done using the following SQL queries:

Delete Schedule Actions

DELETE FROM `wp_posts`
WHERE `post_type` = 'scheduled-action'
AND `post_title` = 'hook_name'

Delete Orphaned Meta

The above query will delete scheduled actions but not their associated meta, so we need to handle that separately with this query:

FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id

Delete Orphaned Log Entries

DELETE comments
FROM wp_comments AS comments
LEFT JOIN wp_posts wp ON wp.ID = comments.comment_post_ID

Changing Currency for WooCommerce Subscriptions

When a store with subscriptions changes currency type, the already-existing subscriptions will maintain their original currency. This is because the currency type is saved as a piece of metadata for each individual subscription.

Example: Due to Brexit, a store needs to change from Euros to Pounds.

  1. Find and edit one of the subscriptions in WooCommerce -> Subscriptions. Confirm that all prices are appearing in the old currency
  2. Use a database management tool (like phpMyAdmin or Ari Adminer) to find the “_order_currency” meta for that subscription. To do that, you would search in the “_postmeta” table by “post_id” by the ID of the subscription. It should contain the code of your previous currency.
  3. Change this value to the new currency code. For example, if you’re changing the subscription with an id=188 from EUR to GBP you could use this SQL query:
    UPDATE wp_postmeta SET ‘meta_value’=’GBP’ WHERE ‘meta_key’=’_order_currency’ AND ‘post_id’=’188’
  4. Edit/reload the subscription again in the admin area and confirm that the prices have been updated to GBP currency
  5. Use the selector in “subscription actions” to Process Renewal.
  6. Check and confirm that the renewal has been processed (a new renewal order should have been generated correctly) and the payment can be found in Stripe dashboard in the new currency.

NOTE: This method does not do price conversion or change prices at all. It simply changes the currency designation. Please don’t edit the database directly unless you take full backups and have a developer level of understanding.

For future bulk editing of subscriptions, please look into AutomateWoo. There are various degrees of bulk editing capabilities, including line items, prices, and currency type, which either already exist or are planned for the future.

WooCommerce adds a post meta row against a coupon for every usage of that coupon

Today while reviewing a site’s database to look for performance bottlenecks, I found 4,000 rows of post meta associated with a single post ID. That meta has the key _used_by and is associated with a post of type 'shop_coupon'

Turns out, WooCommerce keeps a record of all uses of a coupon against the coupon in a separate row of the post meta table. ๐Ÿ˜ฉ

This is an old, and known issue. So hopefully it is addressed before too long.

How to un-cancel a subscription

GOOD NEWS: The manual steps outlined in this tutorial are no longer needed for subscriptions that are still pending cancellation. WooCommerce Subscriptions version 2.5 introduced a way to uncancel a subscription.

Cancelled subscriptions can’t be reactivated from the WordPress admin area. There’s potential to go against the customer’s wishes, for one thing (assuming they cancelled it themselves). Another is that for gateways which aren’t tokenized, such as PayPal Standard, the cancellation of the subscription happens immediately in PayPal, and the ‘pending-cancel’ status is only relevant in the WooCommerce store to give this customer access to any restricted content until the end of their pre-paid term. Being able to reactivate a cancelled subscription (which also includes those that are status ‘pending-cancel’) from the UI is something that might be added in the future for subscriptions which have a tokenized gateway.

In the mean time, if the situation deems that this must be (and can be) done, you can:

  • In the wp_posts table in the database, change the subscription’s post_status from wc-cancelled or wc-pending-cancel to wc-on-hold
  • In the wp_postmeta table in the database, check the subscription’s dates. If there are _schedule_end or _schedule_cancelled dates, change them to `0`. Update the _schedule_next_payment if necessary.
  • From the admin area, reactivate the subscription, or from custom code call $subscription->update_status( 'active' );

Note: this is only ever possible when the payment gateway used on the subscription supports payment date modifications, which many, but not all, gateways support. Notably, it will not be possible with PayPal Standard.

Out-of-Date Version Juggling for Subscriptions & WooCommerce ๐Ÿƒ

To upgrade from really out-of-date versions of Subscriptions & WooCommerce is hard. WooCommerce often breaks backward compatibility, meaning you need to juggle versions.

Below is an upgrade path to go from Subscriptions version 1.4.2 and WooCommerce 2.0.n to WooCommerce 3.0.n and Subscriptions 2.2.n.

  1. Subscriptions 1.4.2 -> 1.4.7 (full compatibility with WC 2.1)
  2. WooCommerce 2.0.x -> 2.1.12
  3. Subscriptions 1.4.7 -> 1.5.10 (full compatibility with WC 2.2)
  4. WooCommerce 2.1.12 -> 2.2.11
  5. Subscriptions 1.5.15 -> 1.5.19 (full compatibility with WC 2.3)
  6. WooCommerce 2.2.11 -> 2.3.13
  7. Subscriptions 1.5.19 -> 1.5.29 (full compatibility with WC 2.3)
  8. WooCommerce 2.3.13 -> 2.4.13
  9. Subscriptions 1.5.29 -> 2.0.9 (full compatibility with WC 2.5)
  10. WooCommerce 2.4.13 -> 2.5.5
  11. Subscriptions 2.0.9 -> 2.0.15 (full compatibility with WC 2.6)
  12. WooCommerce 2.5.5 -> 2.6.14
  13. Subscriptions 2.0.15 -> 2.2.4 (full compatibility with WC 3.0)
  14. WooCommerce 2.6.14 -> 3.0.3

ALTERNATE_WP_CRON runs inconsistently with standard WP-Cron

When the ALTERNATE_WP_CRON constant is defined, WordPress will run WP-Cron on init hook with priority 10 (the default).

Unfortunately, this means any code hooked to init with priority 10 or higher will not be run before processing WP-Cron requests via the alternative WP-Cron method. This is a known issue with an open Trac ticket.

In the case of Subscriptions, where WP-Cron is the backbone for renewals, this can cause all sorts of issues. One such (very hard to diagnose) issue with PayPal subscriptions is addressed with PR 1733 and a similar, older issue is addressed in Action Scheduler with PR 24.

Customise strings in Subscriptions without code

There is a free plugin called Say What that allows store owners to:

alter strings on your site without editing WordPress core, or plugin code

Seems pretty handy for those occasional requests we get for “How to make X say Y?“.

Although it’s obviously not future proof…

Mentioned in Ticket 484278.

How to get Spotlight to index .md files

I’ve been doing a lot of writing in markdown lately and only just noticed that Spotlight wasn’t indexing my *.md files.

Googling for an answer there were quite a few hit’n’miss solutions that didn’t quite seem to work. One being A Yosemite Markdown Spotlight Importer which seemed perfect but for some reason didn’t nail it for me.

I eventually came across How to Force Spotlight to Index Markdown Files in El Capitan which tweaked Lipschitz’s solution, clarifying an important piece of the puzzle:

This is important: Donโ€™t move it to the โ€œuserโ€ directory as Lipschitz suggests (~/Library/Spotlight)โ€”put it in the Systemโ€™s Library folder (/Library/Spotlight)

This seemed to work flawlessly, and now all my Markdown files are being indexed.

Browser Redirect Limits

Different browsers have different redirect limits.

Most are around the 20-21 mark but IE and Safari are different (I can’t vouch for accuracy of these):

  • Chrome 49, 21 redirects
  • Chrome Canary 49, 21 redirects
  • Chrome Canary 51, 21 redirects
  • Firefox 43, 20 redirects
  • Firefox 45, 20 redirects
  • IE 8, 11 redirects ( ๐Ÿ˜ฑ
  • IE 9, 121 redirects ( ๐Ÿ˜ฑ
  • IE 10, 121 redirects ( ๐Ÿ˜ฑ
  • IE 11, 110 redirects ๐Ÿ˜ฑ
  • Opera 28, 21 redirects
  • Opera 36, 21 redirects
  • Safari 5.1.7, 16 redirects
  • (Google Nexus 5, Samsung Galaxy S5, Galaxy Tab 4), 21 redirects


Older Posts