get_woocommerce_api_url()WC 2.1

Get the URL to the WooCommerce REST API.

No Hooks.

Return

String. the URL.

Usage

get_woocommerce_api_url( $path );
$path(string) (required)
an endpoint to include in the URL.

Changelog

Since 2.1 Introduced.

get_woocommerce_api_url() code WC 8.7.0

function get_woocommerce_api_url( $path ) {
	if ( Constants::is_defined( 'WC_API_REQUEST_VERSION' ) ) {
		$version = Constants::get_constant( 'WC_API_REQUEST_VERSION' );
	} else {
		$version = substr( WC_API::VERSION, 0, 1 );
	}

	$url = get_home_url( null, "wc-api/v{$version}/", is_ssl() ? 'https' : 'http' );

	if ( ! empty( $path ) && is_string( $path ) ) {
		$url .= ltrim( $path, '/' );
	}

	return $url;
}