【问题标题】:Call function of the class, which can't call other functions within the class类的调用函数,不能调用类内的其他函数
【发布时间】:2017-11-25 11:28:44
【问题描述】:

我正在尝试调整 WP Woocommerce 预订插件并添加从 Google 日历 API 获取事件的功能。

有课

WC_Bookings_Google_Calendar_Integration 类扩展了 WC_Integration

,提供令牌获取和授权。

我在类中添加了新功能

公共函数 get_googlecal_bookings( $bookable_product, $min_date = 0, $max_date = 0)

假设检索特定产品最小和最大日期之间的所有预订。

从我的functions.php我用

调用它

$existing_bookings = WC_Bookings_Google_Calendar_Integration::get_googlecal_bookings($bookable_product, $从,$到);

这适用于虚拟数据。

虽然,当我尝试在 function get_googlecal_bookings 中使用其他类函数时,例如 $api_url = $this->calendars_uri . $this->calendar_id . '/events/';$access_token = $this->get_access_token();,我什么也得不到。

我知道我叫错了,只需要指出正确的方向

【问题讨论】:

    标签: php wordpress woocommerce woocommerce-bookings


    【解决方案1】:

    您将其调用为静态函数 WC_Bookings_Google_Calendar_Integration::get_googlecal_bookings,但您引用的是 $this,这将不起作用,因为没有实例。

    【讨论】:

    • 谢谢!将其更改为` $foo = new WC_Bookings_Google_Calendar_Integration; $existing_bookings = $foo->get_googlecal_bookings($bookable_product, $from, $to);`
    • 是的,确实如此。我需要更多地了解 OOP。我赞成您的回答,但没有足够的声誉来展示这一点。对不起:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多