wc_display_item_downloads() WC 3.0.0
Display item download links.
Хуки из функции
Возвращает
Строку/null.
Использование
wc_display_item_downloads( $item, $args );
- $item(WC_Order_Item) (обязательный)
- Order Item.
- $args(массив)
- Arguments.
Список изменений
С версии 3.0.0 | Введена. |
Код wc_display_item_downloads() wc display item downloads WC 5.0.0
function wc_display_item_downloads( $item, $args = array() ) {
$strings = array();
$html = '';
$args = wp_parse_args(
$args,
array(
'before' => '<ul class ="wc-item-downloads"><li>',
'after' => '</li></ul>',
'separator' => '</li><li>',
'echo' => true,
'show_url' => false,
)
);
$downloads = is_object( $item ) && $item->is_type( 'line_item' ) ? $item->get_item_downloads() : array();
if ( $downloads ) {
$i = 0;
foreach ( $downloads as $file ) {
$i ++;
if ( $args['show_url'] ) {
$strings[] = '<strong class="wc-item-download-label">' . esc_html( $file['name'] ) . ':</strong> ' . esc_html( $file['download_url'] );
} else {
/* translators: %d: downloads count */
$prefix = count( $downloads ) > 1 ? sprintf( __( 'Download %d', 'woocommerce' ), $i ) : __( 'Download', 'woocommerce' );
$strings[] = '<strong class="wc-item-download-label">' . $prefix . ':</strong> <a href="' . esc_url( $file['download_url'] ) . '" target="_blank">' . esc_html( $file['name'] ) . '</a>';
}
}
}
if ( $strings ) {
$html = $args['before'] . implode( $args['separator'], $strings ) . $args['after'];
}
$html = apply_filters( 'woocommerce_display_item_downloads', $html, $item, $args );
if ( $args['echo'] ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $html;
} else {
return $html;
}
}