本文整理匯總了PHP中WC_Webhook::get_delivery_logs方法的典型用法代碼示例。如果您正苦於以下問題:PHP WC_Webhook::get_delivery_logs方法的具體用法?PHP WC_Webhook::get_delivery_logs怎麽用?PHP WC_Webhook::get_delivery_logs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WC_Webhook
的用法示例。
在下文中一共展示了WC_Webhook::get_delivery_logs方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_items
/**
* Get all webhook deliveries.
*
* @param WP_REST_Request $request
* @return array
*/
public function get_items($request)
{
$webhook = new WC_Webhook((int) $request['webhook_id']);
if (empty($webhook->post_data->post_type) || 'shop_webhook' !== $webhook->post_data->post_type) {
return new WP_Error('woocommerce_rest_webhook_invalid_id', __('Invalid webhook id.', 'woocommerce'), array('status' => 404));
}
$logs = $webhook->get_delivery_logs();
$data = array();
foreach ($logs as $log) {
$delivery = $this->prepare_item_for_response((object) $log, $request);
$delivery = $this->prepare_response_for_collection($delivery);
$data[] = $delivery;
}
return rest_ensure_response($data);
}
示例2: get_webhook_deliveries
/**
* Get deliveries for a webhook
*
* @since 2.2
* @param string $webhook_id webhook ID
* @param string|null $fields fields to include in response
* @return array
*/
public function get_webhook_deliveries($webhook_id, $fields = null)
{
// Ensure ID is valid webhook ID
$webhook_id = $this->validate_request($webhook_id, 'shop_webhook', 'read');
if (is_wp_error($webhook_id)) {
return $webhook_id;
}
$webhook = new WC_Webhook($webhook_id);
$logs = $webhook->get_delivery_logs();
$delivery_logs = array();
foreach ($logs as $log) {
// Add timestamp
$log['created_at'] = $this->server->format_datetime($log['comment']->comment_date_gmt);
// Remove comment object
unset($log['comment']);
$delivery_logs[] = $log;
}
return array('webhook_deliveries' => $delivery_logs);
}