WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_Product::set_downloads() public WC 3.0.0

Set downloads.

{} Это метод класса: WC_Product{}

Хуков нет.

Возвращает

Null. Ничего.

Использование

$WC_Product = new WC_Product();
$WC_Product->set_downloads( $downloads_array );
$downloads_array(массив) (обязательный)
Array of WC_Product_Download objects or arrays.

Список изменений

С версии 3.0.0 Введена.

Код WC_Product::set_downloads() WC 4.7.0

<?php
public function set_downloads( $downloads_array ) {
	$downloads = array();
	$errors    = array();

	foreach ( $downloads_array as $download ) {
		if ( is_a( $download, 'WC_Product_Download' ) ) {
			$download_object = $download;
		} else {
			$download_object = new WC_Product_Download();

			// If we don't have a previous hash, generate UUID for download.
			if ( empty( $download['download_id'] ) ) {
				$download['download_id'] = wp_generate_uuid4();
			}

			$download_object->set_id( $download['download_id'] );
			$download_object->set_name( $download['name'] );
			$download_object->set_file( $download['file'] );
		}

		// Validate the file extension.
		if ( ! $download_object->is_allowed_filetype() ) {
			if ( $this->get_object_read() ) {
				/* translators: %1$s: Downloadable file */
				$errors[] = sprintf( __( 'The downloadable file %1$s cannot be used as it does not have an allowed file type. Allowed types include: %2$s', 'woocommerce' ), '<code>' . basename( $download_object->get_file() ) . '</code>', '<code>' . implode( ', ', array_keys( $download_object->get_allowed_mime_types() ) ) . '</code>' );
			}
			continue;
		}

		// Validate the file exists.
		if ( ! $download_object->file_exists() ) {
			if ( $this->get_object_read() ) {
				/* translators: %s: Downloadable file */
				$errors[] = sprintf( __( 'The downloadable file %s cannot be used as it does not exist on the server.', 'woocommerce' ), '<code>' . $download_object->get_file() . '</code>' );
			}
			continue;
		}

		$downloads[ $download_object->get_id() ] = $download_object;
	}

	if ( $errors ) {
		$this->error( 'product_invalid_download', $errors[0] );
	}

	$this->set_prop( 'downloads', $downloads );
}