Woocommerce PHP Webhook不起作用

时间:2016-02-14 00:20:54

标签: woocommerce webhooks

我在Wordpress中Storefront子主题的functions.php文件中使用此代码。

<?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');

&GT;

我已经在单个php页面上测试了包含到curl_wrap末尾的代码,并在Agile CMS中创建了一个事件。该活动将像聚会或会议,而不是编码活动:)

无论如何,它并没有创造这个事件,我已经尝试了大约四个小时才能让它发挥作用。这里有什么重要的东西吗?我只是想打电话。我意识到通过创建订单(在付款之后)制作派对活动或某事是不合逻辑的。

1 个答案:

答案 0 :(得分: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'); 

&GT;