wccs_upload_file_func_callback

The WooCommerce Checkout Manager wccs upload file func callback function.

Description

wccs_upload_file_func_callback( $order_id ); 

Parameters (1)

0. $order_id
The order id.

Usage

  1. if ( !function_exists( 'wccs_upload_file_func_callback' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/file_upload/main_upload.php'; 
  3.  
  4. // The order id. 
  5. $order_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wccs_upload_file_func_callback($order_id); 
  9.  

Defined (1)

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

/includes/classes/file_upload/main_upload.php  
  1. function wccs_upload_file_func_callback($order_id) { 
  2. global $wpdb, $woocommerce, $post; // this is how you get access to the database 
  3.  
  4. $options = get_option( 'wccs_settings' ); 
  5. $order_id = $_REQUEST["order_id"]; 
  6. $order = new WC_Order( $order_id ); 
  7.  
  8. // load files 
  9. require_once( ABSPATH . 'wp-admin/includes/file.php' );  
  10. require_once( ABSPATH . 'wp-admin/includes/media.php' ); 
  11.  
  12. $upload_dir = wp_upload_dir(); 
  13. $files = $_FILES[''.$_REQUEST["name"].'']; 
  14. $upload_overrides = array( 'test_form' => false ); 
  15.  
  16.  
  17. foreach ($files['name'] as $key => $value) { 
  18. if ($files['name'][$key]) { 
  19.  
  20.  
  21. // using the wp_handle_upload 
  22. if ( empty($options['checkness']['cat_file_upload']) ) {  
  23. $file = array( 
  24. 'name' => $files['name'][$key],  
  25. 'type' => $files['type'][$key],  
  26. 'tmp_name' => $files['tmp_name'][$key],  
  27. error => $files[error][$key],  
  28. 'size' => $files['size'][$key] 
  29. ); 
  30. $movefile = wp_handle_upload($file, $upload_overrides); 
  31.  
  32. $attachment = array( 
  33. 'guid' => $movefile['url'],  
  34. 'post_mime_type' => $movefile['type'],  
  35. 'post_title' => preg_replace( '/\.[^.]+$/', '', basename($movefile['file'])),  
  36. 'post_content' => '',  
  37. 'post_status' => 'inherit' 
  38. ); 
  39.  
  40. $attach_id = wp_insert_attachment( $attachment, $movefile['url'], $order_id); 
  41.  
  42. // you must first include the image.php file 
  43. // for the function wp_generate_attachment_metadata() to work 
  44.  
  45. require_once( ABSPATH . 'wp-admin/includes/image.php' ); 
  46. $attach_data = wp_generate_attachment_metadata( $attach_id, $movefile['url'] ); 
  47. wp_update_attachment_metadata( $attach_id, $attach_data ); 
  48.  
  49. // send email 
  50. $email_recipients = $options['checkness']['wooccm_notification_email']; 
  51. $message_content = ' 
  52. This is an automatic message from WooCommerce Checkout Manager, reporting that files has been uploaded by '.$order->billing_first_name.' '.$order->billing_last_name.'.<br /> 
  53. <h3>Customer Details</h3> 
  54. Name: '.$order->billing_first_name.' '.$order->billing_last_name.'<br /> 
  55. E-mail: '.$order->billing_email.'<br /> 
  56. Order Number: '.$order_id.' <br />  
  57. You can view the files and order details via back-end by following this <a href="'.admin_url('/post.php?post='.$order_id.'&action=edit').'">link</a>. 
  58. '; 
  59.  
  60. wp_mail( $email_recipients, 'WooCCM - Files Uploaded by Customer ['.$order->billing_first_name.' '.$order->billing_last_name.']', $message_content ); 
  61.  
  62. // Reset content-type to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578 
  63.  
  64. } else { 
  65.  
  66. // using move_uploaded_file to categorized uploaded images 
  67. if (!file_exists($upload_dir['basedir']. '/wooccm_uploads/'.$order_id.'/')) { 
  68. wp_mkdir_p($upload_dir['basedir']. '/wooccm_uploads/'.$order_id.'/'); 
  69.  
  70. $filename = $files['name'][$key]; 
  71. $wp_filetype = wp_check_filetype($filename); 
  72. $URLpath = $upload_dir['baseurl']. '/wooccm_uploads/'.$order_id.'/'.$filename; 
  73.  
  74. move_uploaded_file( $files["tmp_name"][$key], $upload_dir['basedir']. '/wooccm_uploads/'.$order_id.'/'.$filename); 
  75.  
  76. $attachment = array( 
  77. 'guid' => $URLpath,  
  78. 'post_mime_type' => $wp_filetype['type'],  
  79. 'post_title' => preg_replace( '/\.[^.]+$/', '', $filename),  
  80. 'post_content' => '',  
  81. 'post_status' => 'inherit' 
  82. ); 
  83.  
  84. $attach_id = wp_insert_attachment( $attachment, $URLpath, $order_id); 
  85.  
  86. // you must first include the image.php file 
  87. // for the function wp_generate_attachment_metadata() to work 
  88.  
  89.  
  90. require_once( ABSPATH . 'wp-admin/includes/image.php' ); 
  91. $attach_data = wp_generate_attachment_metadata( $attach_id, $URLpath ); 
  92. wp_update_attachment_metadata( $attach_id, $attach_data ); 
  93. // send email 
  94. $email_recipients = get_option('admin_email'); 
  95. $message_content = ' 
  96. This is an automatic message from WooCommerce Checkout Manager, reporting that files has been uploaded by '.$order->billing_first_name.' '.$order->billing_last_name.'.<br /> 
  97. <h3>Customer Details</h3> 
  98. Name: '.$order->billing_first_name.' '.$order->billing_last_name.'<br /> 
  99. E-mail: '.$order->billing_email.'<br /> 
  100. Order Number: '.$order_id.' <br />  
  101. You can view the files and order details via back-end by following this <a href="'.admin_url('/post.php?post='.$order_id.'&action=edit').'">link</a>. 
  102. '; 
  103.  
  104. wp_mail( $email_recipients, 'WooCCM - Files Uploaded by Customer', $message_content ); 
  105.  
  106. // Reset content-type to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578 
  107.  
  108. }} 
  109. echo ' '.__('Files was uploaded successfully.', 'woocommerce-checkout-manager').''; 
  110. die();