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' ) ) exit; // Exit if accessed directly
 14 
 15 class WC_Meta_Box_Order_Actions {
 16 
 17     /**
 18      * Output the metabox
 19      */
 20     public static function output( $post ) {
 21         global $woocommerce, $theorder, $wpdb;
 22 
 23         if ( ! is_object( $theorder ) )
 24             $theorder = new WC_Order( $post->ID );
 25 
 26         $order = $theorder;
 27         ?>
 28         <ul class="order_actions submitbox">
 29 
 30             <?php do_action( 'woocommerce_order_actions_start', $post->ID ); ?>
 31 
 32             <li class="wide" id="actions">
 33                 <select name="wc_order_action">
 34                     <option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option>
 35                     <optgroup label="<?php _e( 'Resend order emails', 'woocommerce' ); ?>">
 36                         <?php
 37                                         $mailer = WC()->mailer();
 38 
 39                         $available_emails = apply_filters( 'woocommerce_resend_order_emails_available', array( 'new_order', 'customer_processing_order', 'customer_completed_order', 'customer_invoice' ) );
 40                         $mails = $mailer->get_emails();
 41 
 42                         if ( ! empty( $mails ) ) {
 43                             foreach ( $mails as $mail ) {
 44                                 if ( in_array( $mail->id, $available_emails ) ) {
 45                                     echo '<option value="send_email_'. esc_attr( $mail->id ) .'">' . esc_html( $mail->title ) . '</option>';
 46                                 }
 47                             }
 48                         }
 49                         ?>
 50                     </optgroup>
 51                     <option value="regenerate_download_permissions"><?php _e( 'Generate Download Permissions', 'woocommerce' ); ?></option>
 52                     <?php foreach( apply_filters( 'woocommerce_order_actions', array() ) as $action => $title ) { ?>
 53                         <option value="<?php echo $action; ?>"><?php echo $title; ?></option>
 54                     <?php } ?>
 55                 </select>
 56 
 57                 <button class="button wc-reload" title="<?php _e( 'Apply', 'woocommerce' ); ?>"><span><?php _e( 'Apply', 'woocommerce' ); ?></span></button>
 58             </li>
 59 
 60             <li class="wide">
 61                 <div id="delete-action"><?php
 62                     if ( current_user_can( "delete_post", $post->ID ) ) {
 63                         if ( ! EMPTY_TRASH_DAYS )
 64                             $delete_text = __( 'Delete Permanently', 'woocommerce' );
 65                         else
 66                             $delete_text = __( 'Move to Trash', 'woocommerce' );
 67                         ?><a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo $delete_text; ?></a><?php
 68                     }
 69                 ?></div>
 70 
 71                 <input type="submit" class="button save_order button-primary tips" name="save" value="<?php _e( 'Save Order', 'woocommerce' ); ?>" data-tip="<?php _e( 'Save/update the order', 'woocommerce' ); ?>" />
 72             </li>
 73 
 74             <?php do_action( 'woocommerce_order_actions_end', $post->ID ); ?>
 75 
 76         </ul>
 77         <?php
 78     }
 79 
 80     /**
 81      * Save meta box data
 82      */
 83     public static function save( $post_id, $post ) {
 84         // Order data saved, now get it so we can manipulate status
 85         $order = new WC_Order( $post_id );
 86 
 87         // Handle button actions
 88         if ( ! empty( $_POST['wc_order_action'] ) ) {
 89 
 90             $action = wc_clean( $_POST['wc_order_action'] );
 91 
 92             if ( strstr( $action, 'send_email_' ) ) {
 93 
 94                 do_action( 'woocommerce_before_resend_order_emails', $order );
 95 
 96                 // Ensure gateways are loaded in case they need to insert data into the emails
 97                 WC()->payment_gateways();
 98                 WC()->shipping();
 99 
100                 // Load mailer
101                 $mailer = WC()->mailer();
102 
103                 $email_to_send = str_replace( 'send_email_', '', $action );
104 
105                 $mails = $mailer->get_emails();
106 
107                 if ( ! empty( $mails ) ) {
108                     foreach ( $mails as $mail ) {
109                         if ( $mail->id == $email_to_send ) {
110                             $mail->trigger( $order->id );
111                         }
112                     }
113                 }
114 
115                 do_action( 'woocommerce_after_resend_order_email', $order, $email_to_send );
116 
117             } elseif ( $action == 'regenerate_download_permissions' ) {
118 
119                 delete_post_meta( $post_id, '_download_permissions_granted' );
120                 wc_downloadable_product_permissions( $post_id );
121 
122             } else {
123 
124                 do_action( 'woocommerce_order_action_' . sanitize_title( $action ), $order );
125 
126             }
127         }
128     }
129 }
WooCommerce API documentation generated by ApiGen 2.8.0