wccs_file_uploader_front_end

The WooCommerce Checkout Manager wccs file uploader front end function.

Description

wccs_file_uploader_front_end( $order_id ); 

Parameters (1)

0. $order_id
The order id.

Usage

  1. if ( !function_exists( 'wccs_file_uploader_front_end' ) ) { 
  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_file_uploader_front_end($order_id); 
  9.  

Defined (1)

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

/includes/classes/file_upload/main_upload.php  
  1. function wccs_file_uploader_front_end($order_id) { 
  2. global $wpdb, $thepostid, $theorder, $woocommerce, $post; 
  3.  
  4. $order = new WC_Order($order_id); 
  5.  
  6. $options = get_option( 'wccs_settings' ); 
  7. $length = (empty( $options['checkness']['file_upload_number'])) ? 'this.files.length' : $options['checkness']['file_upload_number']; 
  8.  
  9. $file_types = explode(", ", $options['checkness']['file_types']); 
  10. $number_of_types = count($file_types); 
  11.  
  12. $prefix = 'wc-'; 
  13.  
  14. if ( empty($options['checkness']['upload_os']) || ($order->post_status == $prefix.$options['checkness']['upload_os']) ) { 
  15.  
  16. $upload_dir = wp_upload_dir(); 
  17. $args = array( 
  18. 'post_type' => 'attachment',  
  19. 'numberposts' => -1,  
  20. 'post_status' => null,  
  21. 'post_parent' => $order_id 
  22. ); 
  23. ?>  
  24.  
  25. <script type="text/javascript" > 
  26. jQuery(document).ready(function($) { 
  27.  
  28. $('#wccm_save_order_submit').click(function() { 
  29. $(".wccm_results").html("Deleting files, please wait...."); 
  30. var ajaxurl = '<?php echo admin_url('/admin-ajax.php'); ?>'; 
  31. data = { 
  32. action: 'update_attachment_wccm',  
  33. product_image_gallery : $('#product_image_gallery').val(),  
  34. wccm_default_keys_load : $('#wccm_default_keys_load').val() 
  35. }; 
  36.  
  37. // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php 
  38. $.post(ajaxurl, data, function(response) { 
  39. $(".wccm_results").html(response); 
  40. }); 
  41. }); });  
  42. </script> 
  43.  
  44. <?php wp_enqueue_style( 'wccm_upload_file_style', plugins_url('/woocommerce-checkout-manager/includes/classes/file_upload/file_editing_table.css') ); ?> 
  45.  
  46. <h2><?php echo (empty($options['checkness']['upload_title'])) ? 'Order Uploaded Files' : esc_attr($options['checkness']['upload_title']); ?></h2> 
  47. <div class="woocommerce_order_items_wrapper front_end"> 
  48. <table class="woocommerce_order_items front_end"> 
  49. <thead> 
  50. <tr> 
  51. <th style="width:12%"><?php _e('File Image', 'woocommerce-checkout-manager'); ?></th> 
  52. <th style="width:10%"><?php _e('Action', 'woocommerce-checkout-manager'); ?></th> 
  53. <th style="width:12%"><?php _e('Width x Height', 'woocommerce-checkout-manager'); ?></th> 
  54. <th style="width:8%"><?php _e('Extension', 'woocommerce-checkout-manager'); ?></th> 
  55. <th style="width:15%;text-align: center;"><?php _e('ID #', 'woocommerce-checkout-manager'); ?></th> 
  56. <th style="width:4%"><?php _e('Link', 'woocommerce-checkout-manager'); ?></th> 
  57. <th style="width:30%;text-align: center;"><?php _e('Name', 'woocommerce-checkout-manager'); ?></th> 
  58. </tr> 
  59. </thead> 
  60.  
  61. <tbody class="product_images front_end"> 
  62. <?php 
  63.  
  64.  
  65. $attachment_args = get_posts( $args );  
  66.  
  67. if ($attachment_args) { 
  68. foreach($attachment_args as $attachment) { 
  69. $array[] = $attachment->ID; 
  70.  
  71. $default_wccm_values = implode(', ', $array); 
  72. $product_image_gallery = implode(', ', $array); 
  73.  
  74. $attachments = array_filter( explode( ', ', $product_image_gallery ) ); 
  75.  
  76. if ( $attachments ) { 
  77. foreach ( $attachments as $attachment_id ) { 
  78.  
  79.  
  80. $image_attributes = wp_get_attachment_url( $attachment_id ); 
  81. $image_attributes2 = wp_get_attachment_image_src( $attachment_id ); 
  82. $filename = basename($image_attributes); 
  83. $wp_filetype = wp_check_filetype($filename); 
  84.  
  85. $value_declear = array_diff(explode( ', ', $default_wccm_values), explode( ', ', $attachment_id)); 
  86.  
  87. echo '<tr class="image wccm_filesli wccmv_' . esc_attr( $attachment_id ) . '"> 
  88.  
  89. <td style="display:none;"><script type="text/javascript"> 
  90. jQuery(document).ready(function() { 
  91.  
  92. jQuery(".wccmx_' . esc_attr( $attachment_id ) . '").click(function() { 
  93. jQuery(".wccmv_' . esc_attr( $attachment_id ) . '").hide(); 
  94. jQuery("#product_image_gallery").val(jQuery("#product_image_gallery").val().replace("'.esc_attr( $attachment_id ).'", "")); 
  95.  
  96. }); 
  97. }); 
  98. </script></td> 
  99.  
  100. <td> 
  101. '.wp_get_attachment_link( $attachment_id, '' , false, false, wp_get_attachment_image( $attachment_id, array(75, 75), true ) ).' 
  102. </td> 
  103.  
  104. <td> 
  105. <a class="delete tips wccm_delete wccmx_' . esc_attr( $attachment_id ) . '" data-tip="' . __( 'Delete image', 'woocommerce' ) . '">' . __( 'Delete', 'woocommerce' ) . '</a> 
  106. </td> 
  107.  
  108. <td>'; 
  109. if($image_attributes2[1] == '') { echo '-';}else{ echo $image_attributes2[1].' x '.$image_attributes2[2];}  
  110. echo '</td> 
  111.  
  112. <td> 
  113. '.$wp_filetype['ext'].' 
  114. </td> 
  115.  
  116. <td> 
  117. '.$attachment_id.' 
  118. </td> 
  119.  
  120. <td> 
  121. '.wp_get_attachment_link( $attachment_id, '' , false, false, 'Link' ).' 
  122. </td> 
  123.  
  124. <td> 
  125. '.preg_replace( '/\.[^.]+$/', '', $filename).' 
  126. </td> 
  127. </tr>'; 
  128. }} 
  129.  
  130. ?> 
  131. </tbody> 
  132.  
  133. <input type="hidden" class="wccm_add_to_list" id="product_image_gallery" name="product_image_gallery" value="<?php echo esc_attr( $product_image_gallery ); ?>" /> 
  134.  
  135. <input type="hidden" id="wccm_default_keys_load" name="wccm_default_keys_load" value="<?php echo esc_attr($default_wccm_values); ?>" /> 
  136.  
  137. </table> 
  138. </div> 
  139.  
  140. <button type="button" id="wccm_save_order_submit" class="file_upload_delete wooccm-btn wooccm-btn-danger delete">Confirm Delete</button> 
  141.  
  142. <span id="wccm_uploader_select"> 
  143. <input type="file" style="display:none;" name="files_wccm" id="files_wccm" multiple /> 
  144. <button type="button" class="file_upload_account wooccm-btn wooccm-btn-primary start" id="files_button_wccm">Upload Files</button> 
  145. </span> 
  146.  
  147. <div class="wccm_results front_end"></div>  
  148.  
  149. <div class="clear"></div> 
  150. <?php 
  151. // script for uploading the files 
  152. echo '<script type="text/javascript"> 
  153. jQuery(document).ready(function($) { 
  154. (function post_image_content() { 
  155. var input = document.getElementById("files_wccm"),  
  156. formdata = false;  
  157.  
  158. $("#files_button_wccm").click( function() { 
  159. $("#wccm_uploader_select input[type=file]").click(); 
  160. return false; 
  161. }); 
  162.  
  163. if (window.FormData) { 
  164. formdata = new FormData(); 
  165.  
  166. input.addEventListener("change", function (evt) { 
  167. $("#wccm_uploader_select").block({message: null, overlayCSS: {background: "#fff url(" + woocommerce_params.plugin_url + "/assets/images/ajax-loader.gif) no-repeat center", opacity: 0.6}}); 
  168.  
  169. $("#wccm_uploader_select").block({message: null, overlayCSS: {background: "#fff url(" + woocommerce_params.ajax_loader_url + ") no-repeat center", opacity: 0.6}}); 
  170.  
  171. var length = '.$length.'; 
  172. var file_array = '.wooccm_js_array($file_types).'; 
  173. var wooempt = '.$file_types.'; 
  174.  
  175.  
  176. for ( i = 0; i < length; i++ ) { 
  177. file = this.files[i]; 
  178. for(x=0; x < '.$number_of_types.'; x++) { 
  179. if( !wooempt || file.type.match(file_array[x]) ) { 
  180. if (formdata) { 
  181. formdata.append("files_wccm[]", file);  
  182.  
  183. if (formdata) { 
  184. $.ajax({ 
  185. url: "'.admin_url('/admin-ajax.php?action=wccs_upload_file_func&order_id='.$order_id.'&name=files_wccm').'",  
  186. type: "POST",  
  187. data: formdata,  
  188. processData: false,  
  189. contentType: false,  
  190. success: function (res) { 
  191. $("#files_wccm").show(); 
  192.  
  193. $.ajax({ 
  194. url: "'.$order->get_view_order_url().'",  
  195. data: {},  
  196. success: function (data) { 
  197.  
  198. $("div.woocommerce_order_items_wrapper.front_end").html($(data).find("div.woocommerce_order_items_wrapper.front_end")); 
  199. jQuery("#wccm_uploader_select").unblock(); 
  200. },  
  201. dataType: "html" 
  202. }); 
  203. }); 
  204. }, false); 
  205. }()); 
  206. }); 
  207. </script>'; 
  208. // end script 
  209. // ------------