wc_downloadable_product_permissions

Order Status completed - GIVE DOWNLOADABLE PRODUCT ACCESS TO CUSTOMER.

Description

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

Parameters (2)

0. $order_id (int)
The order id.
1. $force — Optional. (bool) => false
The force.

Usage

  1. if ( !function_exists( 'wc_downloadable_product_permissions' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php'; 
  3.  
  4. // The order id. 
  5. $order_id = -1; 
  6.  
  7. // The force. 
  8. $force = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_downloadable_product_permissions($order_id, $force); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-functions.php  
  1. function wc_downloadable_product_permissions( $order_id, $force = false ) { 
  2. $order = wc_get_order( $order_id ); 
  3.  
  4. if ( ! $order || ( $order->get_data_store()->get_download_permissions_granted( $order ) && ! $force ) ) { 
  5. return; 
  6.  
  7. if ( $order->has_status( 'processing' ) && 'no' === get_option( 'woocommerce_downloads_grant_access_after_payment' ) ) { 
  8. return; 
  9.  
  10. if ( sizeof( $order->get_items() ) > 0 ) { 
  11. foreach ( $order->get_items() as $item ) { 
  12. $product = $item->get_product(); 
  13.  
  14. if ( $product && $product->exists() && $product->is_downloadable() ) { 
  15. $downloads = $product->get_downloads(); 
  16.  
  17. foreach ( array_keys( $downloads ) as $download_id ) { 
  18. wc_downloadable_file_permission( $download_id, $product, $order, $item->get_quantity() ); 
  19.  
  20. $order->get_data_store()->set_download_permissions_granted( $order, true );