Context:
Given a WordPress website with WooCommerce and WooCommerce Subscriptions, I am attempting to fetch a list of a specific user's subscriptions. Until the recent update, this one line of code has taken care of this for me. Here's is the code that I've been using:
$all_user_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions( $user_id );
Where $user_id is a valid user's ID in WordPress.
The Problem:
We are seeing the following error frequently since the last update:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Start or end times are not integers' in /home/warfarep/public_html/wp-content/plugins/woocommerce-subscriptions/includes/wcs-time-functions.php:332 Stack trace: #0 /home/warfarep/public_html/wp-content/plugins/woocommerce-subscriptions/includes/wcs-time-functions.php(309): wcs_number_of_leap_days('1456308046', 1487930566) #1 /home/warfarep/public_html/wp-content/plugins/woocommerce-subscriptions/includes/wcs-deprecated-functions.php(171): wcs_estimate_periods_between('1456308046', 1487930566, 'year', 'floor') #2 /home/warfarep/public_html/wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscriptions-manager.php(1460): wcs_get_subscription_in_deprecated_structure(Object(WC_Subscription)) #3 /home/warfarep/public_html/wp-content/themes/warfare-plugins-pro-3/functions.php(334): WC_Subscriptions_Manager::get_users_subscriptions('2686') #4 /home/warfarep/public_html/wp-content/themes/warfare-plugins-pro-3/woocommerce/myaccount/my-account.ph in /home/warfarep/public_html/wp-content/plugins/woocommerce-subscriptions/includes/wcs-time-functions.php on line 332
The Question:
If this function no longer works (is deprecated) what can I do to retrieve a list (object, array, whatever) of a specific user's subscriptions without throwing a fatal error?
I believe you can now use the wcs_get_users_subscriptions($user_id)
function to get the Subscriptions object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With