After getting no answer I took a slightly different approach and instead of working with the order I’ve simply taken the cart items instead. This of course doesn’t answer the question, why in the moment we get in this filter-hook, $order->get_items() returns empty array, but it solves the task. So here is the workaround for anyone who needs it.
function custom_woocommerce_webhook_should_deliver($shouldDeliver, $instance, $arg) {
global $woocommerce;
$items = $woocommerce->cart->get_cart(); // we get current cart
$excludeCategories = [16, 17];
foreach ($items as $item_id => $item) {
$term_ids = wp_get_post_terms(
$item['product_id'], 'product_cat', array('fields' => 'ids')
);
$result = array_diff($excludeCategories, $term_ids);
if (count($excludeCategories) !== count($result)) {
$shouldDeliver = false;
break;
}
}
return $shouldDeliver;
}
add_filter('woocommerce_webhook_should_deliver', 'custom_woocommerce_webhook_should_deliver', 10, 3);