wc_get_endpoint_url

Get endpoint URL.

Description

(string) wc_get_endpoint_url( (string) $endpoint, (string) $value = '', (string) $permalink = '' ); 

Gets the URL for an endpoint, which varies depending on permalink settings.

Returns (string)

Parameters (3)

0. $endpoint (string)
The endpoint.
1. $value — Optional. (string) => ''
The value.
2. $permalink — Optional. (string) => ''
The permalink.

Usage

  1. if ( !function_exists( 'wc_get_endpoint_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-page-functions.php'; 
  3.  
  4. // The endpoint. 
  5. $endpoint = ''; 
  6.  
  7. // The value. 
  8. $value = ''; 
  9.  
  10. // The permalink. 
  11. $permalink = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wc_get_endpoint_url($endpoint, $value, $permalink); 
  15.  

Defined (1)

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

/includes/wc-page-functions.php  
  1. function wc_get_endpoint_url( $endpoint, $value = '', $permalink = '' ) { 
  2. if ( ! $permalink ) { 
  3. $permalink = get_permalink(); 
  4.  
  5. // Map endpoint to options 
  6. $endpoint = ! empty( WC()->query->query_vars[ $endpoint ] ) ? WC()->query->query_vars[ $endpoint ] : $endpoint; 
  7. $value = ( get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' ) === $endpoint ) ? wc_edit_address_i18n( $value ) : $value; 
  8.  
  9. if ( get_option( 'permalink_structure' ) ) { 
  10. if ( strstr( $permalink, '?' ) ) { 
  11. $query_string = '?' . parse_url( $permalink, PHP_URL_QUERY ); 
  12. $permalink = current( explode( '?', $permalink ) ); 
  13. } else { 
  14. $query_string = ''; 
  15. $url = trailingslashit( $permalink ) . $endpoint . '/' . $value . $query_string; 
  16. } else { 
  17. $url = add_query_arg( $endpoint, $value, $permalink ); 
  18.  
  19. return apply_filters( 'woocommerce_get_endpoint_url', $url, $endpoint, $value, $permalink );