首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Woocommerce订阅-获取开始日期

Woocommerce订阅-获取开始日期
EN

Stack Overflow用户
提问于 2017-07-24 20:14:23
回答 1查看 4.5K关注 0票数 2

我正在尝试创建一个函数来返回用户订阅的开始日期。我正在使用woocommerce和订阅插件。

我让这段代码正常工作,然而,它在我的debug.log中返回了一个"depreciated“错误--而且加载速度也非常慢:

代码语言:javascript
复制
function subscriber_start_date() {
    global $current_user;
    $user = wp_get_current_user();
    // Set start date to initial value
    $start_date = FALSE;
    // Get ALL subscriptions
    $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions( $user->ID );
    $subscriptions = wcs_get_users_subscriptions( $user->ID );
    if ($subscriptions) {
        // Get the first subscription
        $subscription = array_shift($subscriptions);
        // Get the start date, if set
        $start_date = (isset($subscription['start_date'])) ? $subscription['start_date'] : FALSE;
    }

    return $start_date;
}

在搜索了一下之后,我在文档中发现了这个函数:

代码语言:javascript
复制
WC_Subscription::get_date( 'start' );

但这也给了我一些错误,如下所示:

代码语言:javascript
复制
PHP Strict Standards:  Non-static method WC_Subscription::get_date() should not be called statically in /home/skizzar/public_html/wp-content/plugins/lessons-extension/includes/ls-helpers.php on line 28
PHP Notice:  WC_Subscription::get_date was called with an argument that is <strong>deprecated</strong> since version 2.2.0! The &quot;start&quot; date type parameter has been deprecated to align date types with improvements to date APIs in WooCommerce 3.0, specifically the introduction of a new &quot;date_created&quot; API. Use &quot;date_created&quot; in /home/skizzar/public_html/wp-includes/functions.php on line 4023
PHP Fatal error:  Using $this when not in object context in /home/skizzar/public_html/wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php on line 948

有没有一种简单的方法来获取我错过的订阅开始日期?

更新:当使用'date_created‘而不是'start’时,我得到了以下错误:

代码语言:javascript
复制
PHP Strict Standards:  Non-static method WC_Subscription::get_date() should not be called statically in /home/skizzar/public_html/wp-content/plugins/lessons-extension/includes/ls-helpers.php on line 28
PHP Fatal error:  Using $this when not in object context in /home/skizzar/public_html/wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php on line 948
EN

回答 1

Stack Overflow用户

发布于 2017-07-25 21:54:30

您必须循环访问订阅数组:

$subscriptions = wcs_get_users_subscriptions( $user->ID ); foreach ($subscriptions as $sub)

并获得如下的订阅对象:

$subscription = wcs_get_subscription( $sub->ID );

只有这样,您才能通过函数获取日期,例如:

$subscription->get_date( 'start' );

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45280397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档