wc_downloadable_file_permission()WC 1.0

Grant downloadable product access to the file identified by $download_id.

Хуки из функции

Возвращает

int|true|false. insert id or false on failure.

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

wc_downloadable_file_permission( $download_id, $product, $order, $qty, $item );
$download_id(строка) (обязательный)
File identifier.
$product(int|WC_Product) (обязательный)
Product instance or ID.
$order(WC_Order) (обязательный)
Order data.
$qty(int)
Quantity purchased.
По умолчанию: 1
$item(WC_Order_Item)
Item of the order.
По умолчанию: null

Код wc_downloadable_file_permission() WC 8.7.0

function wc_downloadable_file_permission( $download_id, $product, $order, $qty = 1, $item = null ) {
	if ( is_numeric( $product ) ) {
		$product = wc_get_product( $product );
	}
	$download = new WC_Customer_Download();
	$download->set_download_id( $download_id );
	$download->set_product_id( $product->get_id() );
	$download->set_user_id( $order->get_customer_id() );
	$download->set_order_id( $order->get_id() );
	$download->set_user_email( $order->get_billing_email() );
	$download->set_order_key( $order->get_order_key() );
	$download->set_downloads_remaining( 0 > $product->get_download_limit() ? '' : $product->get_download_limit() * $qty );
	$download->set_access_granted( time() );
	$download->set_download_count( 0 );

	$expiry = $product->get_download_expiry();

	if ( $expiry > 0 ) {
		$from_date = $order->get_date_completed() ? $order->get_date_completed()->format( 'Y-m-d' ) : current_time( 'mysql', true );
		$download->set_access_expires( strtotime( $from_date . ' + ' . $expiry . ' DAY' ) );
	}

	$download = apply_filters( 'woocommerce_downloadable_file_permission', $download, $product, $order, $qty, $item );

	return $download->save();
}