WordPress at Your Fingertips
function is not described

WC_API_Products::get_product_categories() public WC 2.2

Get a listing of product categories

{} It's a method of the class: WC_API_Products{}

Return

Array|WP_Error.

Usage

$WC_API_Products = new WC_API_Products();
$WC_API_Products->get_product_categories( $fields );
$fields(string|null)
fields to limit response to
Default: null

Changelog

Since 2.2 Introduced.

Code of WC_API_Products::get_product_categories() WC 5.6.0

public function get_product_categories( $fields = null ) {
	try {
		// Permissions check
		if ( ! current_user_can( 'manage_product_terms' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_categories', __( 'You do not have permission to read product categories', 'woocommerce' ), 401 );
		}

		$product_categories = array();

		$terms = get_terms( 'product_cat', array( 'hide_empty' => false, 'fields' => 'ids' ) );

		foreach ( $terms as $term_id ) {
			$product_categories[] = current( $this->get_product_category( $term_id, $fields ) );
		}

		return array( 'product_categories' => apply_filters( 'woocommerce_api_product_categories_response', $product_categories, $terms, $fields, $this ) );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}