wc_downloadable_product_permissions()
Order Status completed - give downloadable product access to customer.
Hooks from the function
Returns
null. Nothing (null).
Usage
wc_downloadable_product_permissions( $order_id, $force );
- $order_id(int) (required)
- Order ID.
- $force(true|false)
- Force downloadable permissions.
Default:false
wc_downloadable_product_permissions() wc downloadable product permissions code WC 10.7.0
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( OrderStatus::PROCESSING ) && 'no' === get_option( 'woocommerce_downloads_grant_access_after_payment' ) ) {
return;
}
$line_items = $order->get_items();
if ( count( $line_items ) > 0 ) {
foreach ( $line_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(), $item );
}
}
}
}
$order->get_data_store()->set_download_permissions_granted( $order, true );
do_action( 'woocommerce_grant_product_download_permissions', $order_id );
}