wc_display_item_downloads

Display item download links.

Description

(string|void) wc_display_item_downloads( (WC_Item) $item, (array) $args = array() ); 

Returns (string|void)

Parameters (2)

0. $item (WC_Item)
The item.
1. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'wc_display_item_downloads' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // The item. 
  5. $item = null; 
  6.  
  7. // The args. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_display_item_downloads($item, $args); 
  12.  

Defined (1)

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

/includes/wc-template-functions.php  
  1. function wc_display_item_downloads( $item, $args = array() ) { 
  2. $strings = array(); 
  3. $html = ''; 
  4. $args = wp_parse_args( $args, array( 
  5. 'before' => '<ul class ="wc-item-downloads"><li>',  
  6. 'after' => '</li></ul>',  
  7. 'separator' => '</li><li>',  
  8. 'echo' => true,  
  9. 'show_url' => false,  
  10. ) ); 
  11.  
  12. if ( is_object( $item ) && $item->is_type( 'line_item' ) && ( $downloads = $item->get_item_downloads() ) ) { 
  13. $i = 0; 
  14. foreach ( $downloads as $file ) { 
  15. $i ++; 
  16.  
  17. if ( $args['show_url'] ) { 
  18. $strings[] = '<strong class="wc-item-download-label">' . esc_html( $file['name'] ) . ':</strong> ' . esc_html( $file['download_url'] ); 
  19. } else { 
  20. $prefix = sizeof( $downloads ) > 1 ? sprintf( __( 'Download %d', woocommerce ), $i ) : __( 'Download', woocommerce ); 
  21. $strings[] = '<strong class="wc-item-download-label">' . $prefix . ':</strong> <a href="' . esc_url( $file['download_url'] ) . '" target="_blank">' . esc_html( $file['name'] ) . '</a>'; 
  22.  
  23. if ( $strings ) { 
  24. $html = $args['before'] . implode( $args['separator'], $strings ) . $args['after']; 
  25.  
  26. $html = apply_filters( 'woocommerce_display_item_downloads', $html, $item, $args ); 
  27.  
  28. if ( $args['echo'] ) { 
  29. echo $html; 
  30. } else { 
  31. return $html;