WC_API_Webhooks::get_webhooks_count()publicWC 2.2

Get the total number of webhooks

Method of the class: WC_API_Webhooks{}

No Hooks.

Return

Array|WP_Error.

Usage

$WC_API_Webhooks = new WC_API_Webhooks();
$WC_API_Webhooks->get_webhooks_count( $status, $filter );
$status(string)
-
Default: null
$filter(array)
-
Default: array()

Changelog

Since 2.2 Introduced.

WC_API_Webhooks::get_webhooks_count() code WC 8.7.0

public function get_webhooks_count( $status = null, $filter = array() ) {
	try {
		if ( ! current_user_can( 'manage_woocommerce' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_webhooks_count', __( 'You do not have permission to read the webhooks count', 'woocommerce' ), 401 );
		}

		if ( ! empty( $status ) ) {
			$filter['status'] = $status;
		}

		$query = $this->query_webhooks( $filter );

		return array( 'count' => $query['headers']->total );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}