edd_price

Displays a formatted price for a download.

Description

edd_price( (int) $download_id = 0, (constant) $echo = true, (bool) $price_id = false ); 

Parameters (3)

0. $download_id — Optional. (int)
ID of the download price to show
1. $echo — Optional. (constant) => true
Whether to echo or return the results
2. $price_id — Optional. (bool) => false
Price id for variable pricing

Usage

  1. if ( !function_exists( 'edd_price' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'easy-digital-downloads/includes/download-functions.php'; 
  3.  
  4. // ID of the download price to show 
  5. $download_id = -1; 
  6.  
  7. // Whether to echo or return the results 
  8. $echo = true; 
  9.  
  10. // Optional price id for variable pricing 
  11. $price_id = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = edd_price($download_id, $echo, $price_id); 
  15.  

Defined (1)

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

/includes/download-functions.php  
  1. function edd_price( $download_id = 0, $echo = true, $price_id = false ) { 
  2.  
  3. if( empty( $download_id ) ) { 
  4. $download_id = get_the_ID(); 
  5.  
  6. if ( edd_has_variable_prices( $download_id ) ) { 
  7.  
  8. $prices = edd_get_variable_prices( $download_id ); 
  9.  
  10. if ( false !== $price_id && isset( $prices[$price_id] ) ) { 
  11.  
  12. $price = edd_get_price_option_amount( $download_id, $price_id ); 
  13.  
  14. } elseif( $default = edd_get_default_variable_price( $download_id ) ) { 
  15.  
  16. $price = edd_get_price_option_amount( $download_id, $default ); 
  17.  
  18. } else { 
  19.  
  20. $price = edd_get_lowest_price_option( $download_id ); 
  21.  
  22.  
  23. $price = edd_sanitize_amount( $price ); 
  24.  
  25. } else { 
  26.  
  27. $price = edd_get_download_price( $download_id ); 
  28.  
  29.  
  30. $price = apply_filters( 'edd_download_price', edd_sanitize_amount( $price ), $download_id, $price_id ); 
  31. $formatted_price = '<span class="edd_price" id="edd_price_' . $download_id . '">' . $price . '</span>'; 
  32. $formatted_price = apply_filters( 'edd_download_price_after_html', $formatted_price, $download_id, $price, $price_id ); 
  33.  
  34. if ( $echo ) { 
  35. echo $formatted_price; 
  36. } else { 
  37. return $formatted_price;