【问题标题】:Woocommerce PHP Webhook Not workingWoocommerce PHP Webhook 不工作
【发布时间】:2016-05-25 00:57:53
【问题描述】:

我在 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');

?>

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

无论如何,它不会创建事件,我已经尝试了大约四个小时才能让它工作。我在这里缺少什么重要的东西吗?我只是想打电话。我意识到通过创建订单(在他们付款之后)进行派对活动或其他东西是不合逻辑的。

【问题讨论】:

  • 糟糕,将 include 放入函数中。现在它在函数调用之上,但仍然不起作用。
  • 我只需要将操作更改为“woocommerce_new_order”,现在它似乎工作得很好。这是代码:

标签: woocommerce webhooks


【解决方案1】:
<?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'); 

?>

【讨论】:

    猜你喜欢
    • 2015-10-07
    • 2019-04-05
    • 1970-01-01
    • 1970-01-01
    • 2013-02-26
    • 2016-09-18
    • 2019-04-28
    • 2021-05-14
    • 2017-02-11
    相关资源
    最近更新 更多