WC_Webhook::is_valid_resource
Checks the resource for this webhook is valid e.g. valid post status.
Method of the class: WC_Webhook{}
No Hooks.
Returns
true|false. True if validation passes.
Usage
// private - for code of main (parent) class only $result = $this->is_valid_resource( $arg );
- $arg(mixed) (required)
- First hook argument.
Changelog
| Since 3.6.0 | Introduced. |
WC_Webhook::is_valid_resource() WC Webhook::is valid resource code WC 10.6.2
private function is_valid_resource( $arg ) {
$resource = $this->get_resource();
if ( in_array( $resource, array( 'product', 'coupon' ), true ) ) {
$status = get_post_status( absint( $arg ) );
// Ignore auto drafts for all resources.
if ( in_array( $status, array( 'auto-draft', 'new' ), true ) ) {
return false;
}
}
if ( 'order' === $resource ) {
// Check registered order types for order types args.
if ( ! OrderUtil::is_order( absint( $arg ), wc_get_order_types( 'order-webhooks' ) ) ) {
return false;
}
$order = wc_get_order( absint( $arg ) );
// Ignore standard drafts for orders.
if ( in_array( $order->get_status(), array( OrderStatus::DRAFT, OrderStatus::AUTO_DRAFT, 'new' ), true ) ) {
return false;
}
}
return true;
}