2016-02-14 51 views
2

我在Wordpress中的Storefront子主題的myfunction.php文件中使用此代碼。Woocommerce PHP Webhook不工作

<?php 
function action_woocommerce_api_create_order($order_id, $data, $instance) { 
    include get_stylesheet_directory().'/agilephpcode/CurlLib/curlwrap_v2.php'; 
    $event_json = array(
     "start"=>1455256687, 
     "end"=>1455246687, 
     "title"=>"this is a test event", 
     "contacts"=>array(5631986051842048), 
     "allDay"=>false 
    ); 

    $event_json = json_encode($event_json); 
    curl_wrap("events", $event_json, "POST", "application/json"); 
} 

add_action('woocommerce_api_create_order', 'action_woocommerce_api_create_order'); 

?>

我從測試的代碼包含到一個單獨的PHP頁面上的curl_wrap的結束,它會在敏捷CMS的事件。該事件將像聚會或會議,而不是編碼事件:)

無論如何,它不創建事件,我已經嘗試了大約四個小時才能使其工作。有什麼我在這裏失蹤的大事嗎?我只是想打電話。我意識到舉辦派對活動或創建訂單(在他們付款後)是不合邏輯的。

+0

哎呀,把包括函數內。現在它在函數調用之上,但仍然不起作用。 – docaberle

+0

我只需將操作更改爲「woocommerce_new_order」,現在看起來工作得很好。代碼如下: – docaberle

回答

0
<?php 
include get_stylesheet_directory().'/agilephpcode/CurlLib/curlwrap_v2.php'; 
function action_woocommerce_api_create_order($order_id, $data, $instance) { 
    $event_json = array(
     "start"=>1455256687, 
     "end"=>1455246687, 
     "title"=>"this is a test event4", 
     "contacts"=>array(5631986051842048), 
     "allDay"=>false 
    ); 

    $event_json = json_encode($event_json); 
    curl_wrap("events", $event_json, "POST", "application/json"); 
} 

add_action('woocommerce_new_order', 'action_woocommerce_api_create_order'); 

?>