wordpress 如何使用WooCommerce订阅获取特定用户的订阅?

v64noz0r  于 2023-08-03  发布在  WordPress
关注(0)|答案(2)|浏览(174)

上下文:

给定一个带有WooCommerce和WooCommerce订阅的WordPress网站,我试图获取特定用户的订阅列表。直到最近的更新,这一行代码已经为我解决了这个问题。下面是我一直在使用的代码:

$all_user_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions( $user_id );

字符串
其中$user_id是WordPress中有效的用户ID。

问题:

自上次更新以来,我们经常看到以下错误:
致命错误: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堆栈跟踪:#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_period_between('1456308046 ',1487930566,' year ',' floor ')#2 /home/warfarep/public_html/wp-content/plugins/woocommerce-subscributions/includes/class-wc-subscributions-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):© 2019 my-account.ph权利

问题:

如果这个函数不再工作(被弃用),我该怎么做才能检索特定用户订阅的列表(对象,数组,无论什么)而不抛出致命错误?

bjg7j2ky

bjg7j2ky1#

我相信您现在可以使用wcs_get_users_subscriptions($user_id)函数获取Subscriptions对象了。

f45qwnt8

f45qwnt82#

您可以使用以下WC_Subscriptions_Order::get_users_subscription_orders( $user_id );查找活动订阅ID数组
获取更具体的订阅

wcs_get_subscriptions( [
            'subscriptions_per_page' => 10,
            'paged'                  => 1,
            'offset'                 => 0,
            'orderby'                => 'start_date',
            'order'                  => 'DESC',
            'customer_id'            => 0,
            'product_id'             => 0,
            'variation_id'           => 0,
            'order_id'               => 0,
            'subscription_status'    => array( 'any' ),
            'meta_query_relation'    => 'AND',
] );

字符串

相关问题