get_woocommerce_api_url

Get the URL to the WooCommerce REST API.

Description

(string) get_woocommerce_api_url( (string) $path ); 

Returns (string)

the URL.

Parameters (1)

0. $path (string)
An endpoint to include in the URL.

Usage

  1. if ( !function_exists( 'get_woocommerce_api_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php'; 
  3.  
  4. // an endpoint to include in the URL. 
  5. $path = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_woocommerce_api_url($path); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-core-functions.php  
  1. function get_woocommerce_api_url( $path ) { 
  2. $version = defined( 'WC_API_REQUEST_VERSION' ) ? WC_API_REQUEST_VERSION : substr( WC_API::VERSION, 0, 1 ); 
  3.  
  4. $url = get_home_url( null, "wc-api/v{$version}/", is_ssl() ? 'https' : 'http' ); 
  5.  
  6. if ( ! empty( $path ) && is_string( $path ) ) { 
  7. $url .= ltrim( $path, '/' ); 
  8.  
  9. return $url;