2017-11-25 246 views
1

我試圖調整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();我什麼也沒有得到。

我知道,我打電話給他們錯誤的,只是需要點我在正確的方向

回答

0

你調用它作爲一個靜態函數WC_Bookings_Google_Calendar_Integration::get_googlecal_bookings,但你引用$this,它不需額外的工作,因爲there's沒有實例。

+0

謝謝!將其更改爲'$ foo = new WC_Bookings_Google_Calendar_Integration; $ existing_bookings = $ foo-> get_googlecal_bookings($ bookable_product,$ from,$ to);' – altermind

+0

如果有幫助,會很開心。它現在工作嗎? – musashii

+0

是的,它的確如此。我需要更多地進入OOP。我提出了你的答案,但沒有足夠的聲望來表明這一點。對不起:( – altermind

相關問題