2016-11-04 141 views
0

我用WC Integration Class爲我的woocommerce主題創建了一個設置頁面。但是,我現在可以如何訪問存儲的設置?我找不到任何有關這方面的信息,還是我瞎了?如何訪問通過Woocommerce WC Integration保存的數據?

我至今想通了:

// in single product site 
global $woocommerce; 
print_r($woocommerce); 

我發現我的設置作爲一個數組的位置:

$woocommerce->integrations->integrations['integration-my_theme_name']->settings

但我不認爲這是正確的方式獲取數據。我想這會存在一個函數呢?

回答

0

好吧,我發現了一個可接受的解決方案

$my_settings = get_option('woocommerce_{my-used-integration-id}_settings'); 

{my-used-integration-id}是在整合類使用id


示例:整合類(Implementing the WC Integration Class)的

部分:以後

// Integration 
class WC_Integration_Demo_Integration extends WC_Integration { 

    public function __construct() { 
     global $woocommerce; 
     $this->id     = 'foo-bar'; 

     ... 

然後訪問此設置:

$my_settings = get_option('woocommerce_foo-bar_settings'); 

現在$my_settings是一個數組其中包含你所有的r定義字段和值。

相關問題