WC_Meta_Box_Order_Downloads

WC_Meta_Box_Order_Downloads Class.

Defined (1)

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

/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php  
  1. class WC_Meta_Box_Order_Downloads { 
  2.  
  3. /** 
  4. * Output the metabox. 
  5. * @param WP_Post $post 
  6. */ 
  7. public static function output( $post ) { 
  8. global $post, $wpdb; 
  9. ?> 
  10. <div class="order_download_permissions wc-metaboxes-wrapper"> 
  11.  
  12. <div class="wc-metaboxes"><?php 
  13. $data_store = WC_Data_Store::load( 'customer-download' ); 
  14. $download_permissions = $data_store->get_downloads( array( 
  15. 'order_id' => $post->ID,  
  16. 'orderby' => 'product_id',  
  17. ) ); 
  18.  
  19. $product = null; 
  20. $loop = 0; 
  21. $file_counter = 1; 
  22.  
  23. if ( $download_permissions && sizeof( $download_permissions ) > 0 ) { 
  24. foreach ( $download_permissions as $download ) { 
  25. if ( ! $product || $product->get_id() !== $download->get_product_id() ) { 
  26. $product = wc_get_product( $download->get_product_id() ); 
  27. $file_counter = 1; 
  28.  
  29. // don't show permissions to files that have since been removed 
  30. if ( ! $product || ! $product->exists() || ! $product->has_file( $download->get_download_id() ) ) { 
  31. continue; 
  32.  
  33. // Show file title instead of count if set 
  34. $file = $product->get_file( $download->get_download_id() ); 
  35. $file_count = isset( $file['name'] ) ? $file['name'] : sprintf( __( 'File %d', 'woocommerce' ), $file_counter ); 
  36.  
  37. include( 'views/html-order-download-permission.php' ); 
  38.  
  39. $loop++; 
  40. $file_counter++; 
  41. ?></div> 
  42.  
  43. <div class="toolbar"> 
  44. <p class="buttons"> 
  45. <select id="grant_access_id" class="wc-product-search" name="grant_access_id[]" multiple="multiple" style="width: 400px;" data-placeholder="<?php esc_attr_e( 'Search for a downloadable product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_downloadable_products_and_variations"></select> 
  46. <button type="button" class="button grant_access"><?php _e( 'Grant access', 'woocommerce' ); ?></button> 
  47. </p> 
  48. <div class="clear"></div> 
  49. </div> 
  50.  
  51. </div> 
  52. <?php 
  53.  
  54. /** 
  55. * Save meta box data. 
  56. * @param int $post_id 
  57. * @param WP_Post $post 
  58. */ 
  59. public static function save( $post_id, $post ) { 
  60. if ( isset( $_POST['permission_id'] ) ) { 
  61. $permission_ids = $_POST['permission_id']; 
  62. $downloads_remaining = $_POST['downloads_remaining']; 
  63. $access_expires = $_POST['access_expires']; 
  64. $max = max( array_keys( $permission_ids ) ); 
  65.  
  66. for ( $i = 0; $i <= $max; $i ++ ) { 
  67. if ( ! isset( $permission_ids[ $i ] ) ) { 
  68. continue; 
  69. $download = new WC_Customer_Download( $permission_ids[ $i ] ); 
  70. $download->set_downloads_remaining( wc_clean( $downloads_remaining[ $i ] ) ); 
  71. $download->set_access_expires( array_key_exists( $i, $access_expires ) && '' !== $access_expires[ $i ] ? strtotime( $access_expires[ $i ] ) : '' ); 
  72. $download->save();