WC_API_Server::get_index()publicWC 2.1

Get the site index.

This endpoint describes the capabilities of the site.

Method of the class: WC_API_Server{}

Return

Array. Index entity

Usage

$WC_API_Server = new WC_API_Server();
$WC_API_Server->get_index();

Changelog

Since 2.1 Introduced.

WC_API_Server::get_index() code WC 7.7.0

public function get_index() {

	// General site data
	$available = array(
		'store' => array(
			'name'        => get_option( 'blogname' ),
			'description' => get_option( 'blogdescription' ),
			'URL'         => get_option( 'siteurl' ),
			'wc_version'  => WC()->version,
			'routes'      => array(),
			'meta'        => array(
				'timezone'			 => wc_timezone_string(),
				'currency'       	 => get_woocommerce_currency(),
				'currency_format'    => get_woocommerce_currency_symbol(),
				'tax_included'   	 => wc_prices_include_tax(),
				'weight_unit'    	 => get_option( 'woocommerce_weight_unit' ),
				'dimension_unit' 	 => get_option( 'woocommerce_dimension_unit' ),
				'ssl_enabled'    	 => ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) ),
				'permalinks_enabled' => ( '' !== get_option( 'permalink_structure' ) ),
				'links'          	 => array(
					'help' => 'https://woocommerce.github.io/woocommerce/rest-api/',
				),
			),
		),
	);

	// Find the available routes
	foreach ( $this->get_routes() as $route => $callbacks ) {
		$data = array();

		$route = preg_replace( '#\(\?P(<\w+?>).*?\)#', '$1', $route );
		$methods = array();
		foreach ( self::$method_map as $name => $bitmask ) {
			foreach ( $callbacks as $callback ) {
				// Skip to the next route if any callback is hidden
				if ( $callback[1] & self::HIDDEN_ENDPOINT ) {
					continue 3;
				}

				if ( $callback[1] & $bitmask ) {
					$data['supports'][] = $name;
				}

				if ( $callback[1] & self::ACCEPT_DATA ) {
					$data['accepts_data'] = true;
				}

				// For non-variable routes, generate links
				if ( strpos( $route, '<' ) === false ) {
					$data['meta'] = array(
						'self' => get_woocommerce_api_url( $route ),
					);
				}
			}
		}
		$available['store']['routes'][ $route ] = apply_filters( 'woocommerce_api_endpoints_description', $data );
	}
	return apply_filters( 'woocommerce_api_index', $available );
}