WC_API_Coupons::get_coupons_count()publicWC 2.1

Get the total number of coupons

Method of the class: WC_API_Coupons{}

No Hooks.

Return

Array|WP_Error.

Usage

$WC_API_Coupons = new WC_API_Coupons();
$WC_API_Coupons->get_coupons_count( $filter );
$filter(array)
-
Default: array()

Changelog

Since 2.1 Introduced.

WC_API_Coupons::get_coupons_count() code WC 8.6.1

public function get_coupons_count( $filter = array() ) {
	try {
		if ( ! current_user_can( 'read_private_shop_coupons' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_coupons_count', __( 'You do not have permission to read the coupons count', 'woocommerce' ), 401 );
		}

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

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