wc_downloadable_product_permissions( int $order_id, bool $force = false )

Order Status completed – give downloadable product access to customer.


Description Description


Parameters Parameters

$order_id

(Required) Order ID.

$force

(Optional) Force downloadable permissions.

Default value: false


Top ↑

Source Source

File: includes/wc-order-functions.php

function wc_downloadable_product_permissions( $order_id, $force = false ) {
	$order = wc_get_order( $order_id );

	if ( ! $order || ( $order->get_data_store()->get_download_permissions_granted( $order ) && ! $force ) ) {
		return;
	}

	if ( $order->has_status( 'processing' ) && 'no' === get_option( 'woocommerce_downloads_grant_access_after_payment' ) ) {
		return;
	}

	if ( count( $order->get_items() ) > 0 ) {
		foreach ( $order->get_items() as $item ) {
			$product = $item->get_product();

			if ( $product && $product->exists() && $product->is_downloadable() ) {
				$downloads = $product->get_downloads();

				foreach ( array_keys( $downloads ) as $download_id ) {
					wc_downloadable_file_permission( $download_id, $product, $order, $item->get_quantity() );
				}
			}
		}
	}

	$order->get_data_store()->set_download_permissions_granted( $order, true );
	do_action( 'woocommerce_grant_product_download_permissions', $order_id );
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.