/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php

  1. <?php 
  2. /** 
  3. * Order Actions 
  4. * 
  5. * Functions for displaying the order actions meta box. 
  6. * 
  7. * @author WooThemes 
  8. * @category Admin 
  9. * @package WooCommerce/Admin/Meta Boxes 
  10. * @version 2.1.0 
  11. */ 
  12.  
  13. if ( ! defined( 'ABSPATH' ) ) { 
  14. exit; // Exit if accessed directly 
  15.  
  16. /** 
  17. * WC_Meta_Box_Order_Actions Class. 
  18. */ 
  19. class WC_Meta_Box_Order_Actions { 
  20.  
  21. /** 
  22. * Output the metabox. 
  23. * 
  24. * @param WP_Post $post 
  25. */ 
  26. public static function output( $post ) { 
  27. global $theorder; 
  28.  
  29. // This is used by some callbacks attached to hooks such as woocommerce_order_actions which rely on the global to determine if actions should be displayed for certain orders. 
  30. if ( ! is_object( $theorder ) ) { 
  31. $theorder = wc_get_order( $post->ID ); 
  32.  
  33. $order_type_object = get_post_type_object( $post->post_type ); 
  34. ?> 
  35. <ul class="order_actions submitbox"> 
  36.  
  37. <?php do_action( 'woocommerce_order_actions_start', $post->ID ); ?> 
  38.  
  39. <li class="wide" id="actions"> 
  40. <select name="wc_order_action"> 
  41. <option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option> 
  42. <?php 
  43. $mailer = WC()->mailer(); 
  44. $available_emails = apply_filters( 'woocommerce_resend_order_emails_available', array( 'new_order', 'cancelled_order', 'customer_processing_order', 'customer_completed_order', 'customer_invoice' ) ); 
  45. $mails = $mailer->get_emails(); 
  46.  
  47. if ( ! empty( $mails ) && ! empty( $available_emails ) ) { ?> 
  48. <optgroup label="<?php esc_attr_e( 'Resend order emails', 'woocommerce' ); ?>"> 
  49. <?php 
  50. foreach ( $mails as $mail ) { 
  51. if ( in_array( $mail->id, $available_emails ) && 'no' !== $mail->enabled ) { 
  52. echo '<option value="send_email_' . esc_attr( $mail->id ) . '">' . sprintf( __( 'Resend %s', 'woocommerce' ), esc_html( $mail->title ) ) . '</option>'; 
  53. } ?> 
  54. </optgroup> 
  55. <?php 
  56. ?> 
  57.  
  58. <option value="regenerate_download_permissions"><?php _e( 'Regenerate download permissions', 'woocommerce' ); ?></option> 
  59.  
  60. <?php foreach ( apply_filters( 'woocommerce_order_actions', array() ) as $action => $title ) { ?> 
  61. <option value="<?php echo $action; ?>"><?php echo $title; ?></option> 
  62. <?php } ?> 
  63. </select> 
  64.  
  65. <button class="button wc-reload"><span><?php _e( 'Apply', 'woocommerce' ); ?></span></button> 
  66. </li> 
  67.  
  68. <li class="wide"> 
  69. <div id="delete-action"><?php 
  70.  
  71. if ( current_user_can( 'delete_post', $post->ID ) ) { 
  72.  
  73. if ( ! EMPTY_TRASH_DAYS ) { 
  74. $delete_text = __( 'Delete permanently', 'woocommerce' ); 
  75. } else { 
  76. $delete_text = __( 'Move to trash', 'woocommerce' ); 
  77. ?><a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo $delete_text; ?></a><?php 
  78. ?></div> 
  79.  
  80. <input type="submit" class="button save_order button-primary tips" name="save" value="<?php printf( __( 'Save %s', 'woocommerce' ), strtolower( $order_type_object->labels->singular_name ) ); ?>" data-tip="<?php printf( __( 'Save/update the %s', 'woocommerce' ), strtolower( $order_type_object->labels->singular_name ) ); ?>" /> 
  81. </li> 
  82.  
  83. <?php do_action( 'woocommerce_order_actions_end', $post->ID ); ?> 
  84.  
  85. </ul> 
  86. <?php 
  87.  
  88. /** 
  89. * Save meta box data. 
  90. * 
  91. * @param int $post_id 
  92. * @param WP_Post $post 
  93. */ 
  94. public static function save( $post_id, $post ) { 
  95. global $wpdb; 
  96.  
  97. // Order data saved, now get it so we can manipulate status 
  98. $order = wc_get_order( $post_id ); 
  99.  
  100. // Handle button actions 
  101. if ( ! empty( $_POST['wc_order_action'] ) ) { 
  102.  
  103. $action = wc_clean( $_POST['wc_order_action'] ); 
  104.  
  105. if ( strstr( $action, 'send_email_' ) ) { 
  106.  
  107. // Switch back to the site locale. 
  108. if ( function_exists( 'switch_to_locale' ) ) { 
  109. switch_to_locale( get_locale() ); 
  110.  
  111. do_action( 'woocommerce_before_resend_order_emails', $order ); 
  112.  
  113. // Ensure gateways are loaded in case they need to insert data into the emails. 
  114. WC()->payment_gateways(); 
  115. WC()->shipping(); 
  116.  
  117. // Load mailer. 
  118. $mailer = WC()->mailer(); 
  119. $email_to_send = str_replace( 'send_email_', '', $action ); 
  120. $mails = $mailer->get_emails(); 
  121.  
  122. if ( ! empty( $mails ) ) { 
  123. foreach ( $mails as $mail ) { 
  124. if ( $mail->id == $email_to_send ) { 
  125. $mail->trigger( $order->get_id(), $order ); 
  126. /** translators: %s: email title */ 
  127. $order->add_order_note( sprintf( __( '%s email notification manually sent.', 'woocommerce' ), $mail->title ), false, true ); 
  128.  
  129. do_action( 'woocommerce_after_resend_order_email', $order, $email_to_send ); 
  130.  
  131. // Restore user locale. 
  132. if ( function_exists( 'restore_current_locale' ) ) { 
  133. restore_current_locale(); 
  134.  
  135. // Change the post saved message. 
  136. add_filter( 'redirect_post_location', array( __CLASS__, 'set_email_sent_message' ) ); 
  137.  
  138. } elseif ( 'regenerate_download_permissions' === $action ) { 
  139.  
  140. $data_store = WC_Data_Store::load( 'customer-download' ); 
  141. $data_store->delete_by_order_id( $post_id ); 
  142. wc_downloadable_product_permissions( $post_id, true ); 
  143.  
  144. } else { 
  145.  
  146. if ( ! did_action( 'woocommerce_order_action_' . sanitize_title( $action ) ) ) { 
  147. do_action( 'woocommerce_order_action_' . sanitize_title( $action ), $order ); 
  148.  
  149. /** 
  150. * Set the correct message ID. 
  151. * 
  152. * @param string $location 
  153. * 
  154. * @since 2.3.0 
  155. * 
  156. * @static 
  157. * 
  158. * @return string 
  159. */ 
  160. public static function set_email_sent_message( $location ) { 
  161. return add_query_arg( 'message', 11, $location ); 
.