Subscriptions 2.0 changed the way data was stored and instantiated. Because of this, it needed to deprecate a large number of existing hooks.
Some of these hooks had dynamic names, i.e. actions/filters where we don’t know what the hook actually is at run-time because it includes a payment gateway ID or another piece of dynamic data we don’t know in advance. Because of this, there was no choice but to either break backwards compatibility completely for those hooks (which would be severe in the case of scheduled subscription payment hooks) or add a small function to the 'all'
hook to check if it’s a hook we have deprecated and maintain backwards compatibility.
The latter option was chosen as far better, but it may cause performance issues on some sites. We have, however, attempted to mitigate performance issues and also made sure there is a way to remove this code if your site is negatively affected and you know you have no deprecated code running on your site.
Mitigating performance issues
Functions attached to 'all'
, while running many times each request, are minor. They simply check the name of the hook to see if they start with 13 known hook prefixes.
This was done to mitigate any major performance impact on your site. However, depending on the number of plugins running on your site, you may find that running this tiny piece of logic on all hooks markedly reduces site performance. If this is the case, consider removing deprecated handling as outlined below.
Removing deprecated hook handling
If you know your site is not running outdated code, you can avoid having to load both this and other depreciation handling code to improve performance with Subscriptions 2.0.
The snippet below tells Subscriptions not to load deprecated handlers, including classes that attach to the 'all'
hook to handle dynamic hooks:
<?php | |
/** | |
* Plugin Name: WooCommerce Subscriptions Remove Deprecation Handlers | |
* Plugin URI: https://support.woothemes.com/hc/en-us/articles/205214466 | |
* Description: Do not load backward compatibility support in Subscriptions 2.0. | |
* Author: Prospress Inc. | |
* Version: 1.0 | |
* Author URI: http://prospress.com | |
*/ | |
function wcs_remove_deprecation_handlers() { | |
add_filter( ‘woocommerce_subscriptions_load_deprecation_handlers’, ‘__return_false’ ); | |
} | |
add_action( ‘plugins_loaded’, ‘wcs_remove_deprecation_handlers’, 0 ); |
This snippet can also be downloaded and installed as a plugin.
Warning
You must be certain that no third-party or custom code is running on your site that is dependent on deprecated hooks before disabling this deprecated hook handling. Disabling will break backwards compatibility with all old hooks and can, among other things:
- Prevent recurring payments being processed
- Break synchronization of subscription status between the payment gateway and store
- Break updating of a failing payment method
List of Deprecated Hooks
This gist provides a complete list of deprecated hooks, and their new counterpart, formatted as PHP arrays. The new hook is listed as the array key, and the deprecated hook as the value or values.
<?php | |
$deprecated_actions = array( | |
‘woocommerce_scheduled_subscription_payment’ => ‘scheduled_subscription_payment’, | |
‘woocommerce_subscription_payment_complete’ => ‘processed_subscription_payment’, | |
‘woocommerce_subscription_renewal_payment_complete’ => ‘processed_subscription_renewal_payment’, | |
‘woocommerce_subscriptions_paid_for_failed_renewal_order’ => ‘woocommerce_subscriptions_processed_failed_renewal_order_payment’, | |
‘woocommerce_subscriptions_pre_update_payment_method’ => ‘woocommerce_subscriptions_pre_update_recurring_payment_method’, | |
‘woocommerce_subscription_payment_method_updated’ => ‘woocommerce_subscriptions_updated_recurring_payment_method’, | |
‘woocommerce_subscription_failing_payment_method_updated’ => ‘woocommerce_subscriptions_changed_failing_payment_method’, | |
‘woocommerce_subscription_payment_failed’ => ‘processed_subscription_payment_failure’, | |
‘woocommerce_subscription_change_payment_method_via_pay_shortcode’ => ‘woocommerce_subscriptions_change_payment_method_via_pay_shortcode’, | |
‘subscriptions_put_on_hold_for_order’ => ‘subscriptions_suspended_for_order’, | |
‘woocommerce_subscription_status_active’ => ‘activated_subscription’, | |
‘woocommerce_subscription_status_on-hold’ => array( ‘suspended_subscription’, ‘subscription_put_on-hold’ ), | |
‘woocommerce_subscription_status_cancelled’ => ‘cancelled_subscription’, | |
‘woocommerce_subscription_status_on-hold_to_active’ => ‘reactivated_subscription’, | |
‘woocommerce_subscription_status_expired’ => ‘subscription_expired’, | |
‘woocommerce_scheduled_subscription_trial_end’ => ‘subscription_trial_end’, | |
‘woocommerce_scheduled_subscription_end_of_prepaid_term’ => ‘subscription_end_of_prepaid_term’, | |
); | |
$deprecated_filters = array( | |
// Subscription Meta Filters | |
‘woocommerce_subscription_payment_failed_count’ => ‘woocommerce_subscription_failed_payment_count’, | |
‘woocommerce_subscription_payment_completed_count’ => ‘woocommerce_subscription_completed_payment_count’, | |
‘woocommerce_subscription_get_end_date’ => ‘woocommerce_subscription_expiration_date’, | |
‘woocommerce_subscription_get_trial_end_date’ => ‘woocommerce_subscription_trial_expiration_date’, | |
‘woocommerce_subscription_date_updated’ => ‘woocommerce_subscriptions_set_expiration_date’, | |
‘woocommerce_subscriptions_product_expiration_date’ => ‘woocommerce_subscription_calculated_expiration_date’, | |
‘woocommerce_subscription_date_updated’ => ‘woocommerce_subscription_set_next_payment_date’, | |
‘woocommerce_subscription_get_last_payment_date’ => ‘woocommerce_subscription_last_payment_date’, | |
‘woocommerce_subscription_calculated_next_payment_date’ => ‘woocommerce_subscriptions_calculated_next_payment_date’, | |
‘woocommerce_subscription_date_updated’ => ‘woocommerce_subscriptions_set_trial_expiration_date’, | |
‘wcs_subscription_statuses’ => array( | |
‘woocommerce_subscriptions_custom_status_string’, //no replacement as Subscriptions now uses wcs_get_subscription_statuses() for everything (the deprecator could use ‘wc_subscription_statuses’ and loop over all statuses to set it in the returned value) | |
‘woocommerce_subscriptions_status_string’, | |
), | |
// Renewal Filters | |
‘wcs_renewal_order_items’ => ‘woocommerce_subscriptions_renewal_order_items’, | |
‘wcs_renewal_order_meta_query’ => ‘woocommerce_subscriptions_renewal_order_meta_query’, | |
‘wcs_renewal_order_meta’ => ‘woocommerce_subscriptions_renewal_order_meta’, | |
‘wcs_renewal_order_item_name’ => ‘woocommerce_subscriptions_renewal_order_item_name’, | |
‘wcs_users_resubscribe_link’ => ‘woocommerce_subscriptions_users_renewal_link’, | |
‘wcs_can_user_resubscribe_to_subscription’ => ‘woocommerce_can_subscription_be_renewed’, | |
‘wcs_renewal_order_created’ => array( | |
‘woocommerce_subscriptions_renewal_order_created’, // Even though ‘woocommerce_subscriptions_renewal_order_created’ is an action, as it is attached to a filter, we need to handle it in here | |
‘woocommerce_subscriptions_renewal_order_id’, | |
), | |
// List Table Filters | |
‘woocommerce_subscription_list_table_actions’ => ‘woocommerce_subscriptions_list_table_actions’, | |
‘woocommerce_subscription_list_table_column_status_content’ => ‘woocommerce_subscriptions_list_table_column_status_content’, | |
‘woocommerce_subscription_list_table_column_content’ => ‘woocommerce_subscriptions_list_table_column_content’, | |
// User Filters | |
‘wcs_can_user_put_subscription_on_hold’ => ‘woocommerce_subscriptions_can_current_user_suspend’, | |
‘wcs_view_subscription_actions’ => ‘woocommerce_my_account_my_subscriptions_actions’, | |
‘wcs_get_users_subscriptions’ => ‘woocommerce_users_subscriptions’, | |
‘wcs_users_change_status_link’ => ‘woocommerce_subscriptions_users_action_link’, | |
‘wcs_user_has_subscription’ => ‘woocommerce_user_has_subscription’, | |
// Misc Filters | |
‘woocommerce_subscription_max_failed_payments_exceeded’ => ‘woocommerce_subscriptions_max_failed_payments_exceeded’, | |
‘woocommerce_my_subscriptions_payment_method’ => ‘woocommerce_my_subscriptions_recurring_payment_method’, | |
‘woocommerce_subscriptions_update_payment_via_pay_shortcode’ => ‘woocommerce_subscriptions_update_recurring_payment_via_pay_shortcode’, | |
‘woocommerce_can_subscription_be_updated_to’ => ‘woocommerce_can_subscription_be_changed_to’, | |
); | |
/** | |
* The following hooks are prefixes only, the are used a deprecated hooks. Refer to the source code for the suffix on these hooks. | |
*/ | |
$deprecated_hook_prefixes = array( | |
‘woocommerce_admin_changed_subscription_to_’ => ‘admin_changed_subscription_to_’, | |
‘woocommerce_scheduled_subscription_payment_’ => ‘scheduled_subscription_payment_’, | |
‘woocommerce_customer_changed_subscription_to_’ => ‘customer_changed_subscription_to_’, | |
‘woocommerce_subscription_payment_method_updated_to_’ => ‘woocommerce_subscriptions_updated_recurring_payment_method_to_’, | |
‘woocommerce_subscription_payment_method_updated_from_’ => ‘woocommerce_subscriptions_updated_recurring_payment_method_from_’, | |
‘woocommerce_subscription_failing_payment_method_updated_’ => ‘woocommerce_subscriptions_changed_failing_payment_method_’, | |
// Gateway status change hooks | |
‘woocommerce_subscription_activated_’ => array( | |
‘activated_subscription_’, | |
‘reactivated_subscription_’, | |
), | |
‘woocommerce_subscription_on-hold_’ => ‘subscription_put_on-hold_’, | |
‘woocommerce_subscription_cancelled_’ => ‘cancelled_subscription_’, | |
‘woocommerce_subscription_expired_’ => ‘subscription_expired_’, | |
// This is a filter, not an action | |
‘woocommerce_can_subscription_be_updated_to_’ => ‘woocommerce_subscription_can_be_changed_to_’, | |
); |