| @@ -394,8 +394,44 @@ | ||
| 394 | 394 | return false; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
| 398 | + * Merchant opted out of plugin order posting. | |
| 399 | + * | |
| 400 | + * True only when every RouteApp Order Upsert webhook is paused. Missing | |
| 401 | + * webhooks, and Active or Disabled ones, still reconcile: Disabled is | |
| 402 | + * WooCommerce's automatic status after delivery failures. | |
| 403 | + * | |
| 404 | + * @return bool | |
| 405 | + */ | |
| 406 | + public static function is_order_upsert_paused() { | |
| 407 | + if (!class_exists('WC_Data_Store')) { | |
| 408 | + return false; | |
| 409 | + } | |
| 410 | + $data_store = \WC_Data_Store::load('webhook'); | |
| 411 | + $ids = $data_store->search_webhooks(array('limit' => -1)); | |
| 412 | + if (!is_array($ids) || empty($ids)) { | |
| 413 | + return false; | |
| 414 | + } | |
| 415 | + | |
| 416 | + $found = false; | |
| 417 | + foreach ($ids as $id) { | |
| 418 | + $webhook = function_exists('wc_get_webhook') ? wc_get_webhook($id) : false; | |
| 419 | + if (!self::is_webhook_like($webhook, true)) { | |
| 420 | + continue; | |
| 421 | + } | |
| 422 | + if ('RouteApp Order Upsert' !== $webhook->get_name()) { | |
| 423 | + continue; | |
| 424 | + } | |
| 425 | + $found = true; | |
| 426 | + if ('paused' !== $webhook->get_status()) { | |
| 427 | + return false; | |
| 428 | + } | |
| 429 | + } | |
| 430 | + return $found; | |
| 431 | + } | |
| 432 | + | |
| 433 | + /** | |
| 398 | 434 | * Update in place. Do not delete+recreate (that is what duplicated hooks). |
| 399 | 435 | * |
| 400 | 436 | * @param object $webhook WC_Webhook. |
| 401 | 437 | * @param array $values Expected webhook config. |