【问题标题】:Create a webhook programmatically in wordpress/woocommerce在 wordpress/woocommerce 中以编程方式创建 webhook
【发布时间】:2020-04-30 19:06:20
【问题描述】:

我正在制作一个插件来将一个 ERP 集成到 Woocommerce,我正在考虑使用网络挂钩进行该集成,问题是在第一次激活插件时创建网络挂钩,而不是强制人们手动创建 woocommerce webhook 并对其进行配置。我用谷歌搜索并尝试了几件事,但似乎没有人工作,还尝试进行 sql 查询,但没有奏效。

我试过这个:

function createWebhook($userID,$topic,$secret,$deliveryURL,$status)
{
    $webhook = new WC_Webhook();
    $webhook->set_user_id($userID); // User ID used while generating the webhook payload.
    $webhook->set_topic( $topic ); // Event used to trigger a webhook.
    $webhook->set_secret( $secret ); // Secret to validate webhook when received.
    $webhook->set_delivery_url( $deliveryURL ); // URL where webhook should be sent.
    $webhook->set_status( $status ); // Webhook status.
    $save = $webhook->save();
    return $save;
}

来自这个thread

没有成功,得到很多错误。

无论如何,感谢您的帮助。我希望你的啤酒安全健康!

【问题讨论】:

    标签: php wordpress woocommerce webhooks erp


    【解决方案1】:

    您缺少 webhook 名称

    添加$webhook->set_name('Webhook Name');

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-14
      • 2018-08-21
      • 2016-08-12
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多