WC_Webhook::is_valid_resource()privateWC 3.6.0

Checks the resource for this webhook is valid e.g. valid post status.

Method of the class: WC_Webhook{}

No Hooks.

Return

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() code WC 8.9.0

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( 'draft', 'auto-draft', 'new' ), true ) ) {
			return false;
		}
	}
	return true;
}