WC_Meta_Box_Order_Actions

WC_Meta_Box_Order_Actions Class.

Defined (1)

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

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