2013-08-06 10:41:20 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* Order Actions
2013-08-06 10:41:20 +00:00
*
* Functions for displaying the order actions meta box .
*
2014-08-31 07:18:21 +00:00
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin / Meta Boxes
2013-08-06 10:41:20 +00:00
* @ version 2.1 . 0
*/
2014-09-20 20:05:06 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
2013-08-06 10:41:20 +00:00
2014-09-20 20:05:06 +00:00
/**
2015-11-03 12:28:01 +00:00
* WC_Meta_Box_Order_Actions Class .
2014-09-20 20:05:06 +00:00
*/
2013-08-06 10:41:20 +00:00
class WC_Meta_Box_Order_Actions {
/**
2015-11-03 12:28:01 +00:00
* Output the metabox .
2016-01-04 21:31:36 +00:00
*
* @ param WP_Post $post
2013-08-06 10:41:20 +00:00
*/
public static function output ( $post ) {
2015-01-20 01:12:26 +00:00
global $theorder ;
2015-01-20 08:38:13 +00:00
// 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.
2015-01-20 01:12:26 +00:00
if ( ! is_object ( $theorder ) ) {
$theorder = wc_get_order ( $post -> ID );
}
2014-11-26 21:25:15 +00:00
$order_type_object = get_post_type_object ( $post -> post_type );
2013-08-06 10:41:20 +00:00
?>
< ul class = " order_actions submitbox " >
< ? php do_action ( 'woocommerce_order_actions_start' , $post -> ID ); ?>
< li class = " wide " id = " actions " >
< select name = " wc_order_action " >
< option value = " " >< ? php _e ( 'Actions' , 'woocommerce' ); ?> </option>
< ? php
2014-07-04 14:20:29 +00:00
$mailer = WC () -> mailer ();
2015-03-20 15:31:31 +00:00
$available_emails = apply_filters ( 'woocommerce_resend_order_emails_available' , array ( 'new_order' , 'cancelled_order' , 'customer_processing_order' , 'customer_completed_order' , 'customer_invoice' , 'customer_refunded_order' ) );
2014-07-04 14:20:29 +00:00
$mails = $mailer -> get_emails ();
2013-08-06 10:41:20 +00:00
2016-11-30 10:32:38 +00:00
if ( ! empty ( $mails ) && ! empty ( $available_emails ) ) { ?>
< optgroup label = " <?php esc_attr_e( 'Resend order emails', 'woocommerce' ); ?> " >
< ? php
2013-08-06 10:41:20 +00:00
foreach ( $mails as $mail ) {
2016-04-25 12:22:31 +00:00
if ( in_array ( $mail -> id , $available_emails ) && 'no' !== $mail -> enabled ) {
2016-12-15 16:44:43 +00:00
echo '<option value="send_email_' . esc_attr ( $mail -> id ) . '">' . sprintf ( __ ( 'Resend %s' , 'woocommerce' ), esc_html ( $mail -> title ) ) . '</option>' ;
2013-08-06 10:41:20 +00:00
}
2016-11-30 10:32:38 +00:00
} ?>
</ optgroup >
< ? php
2013-08-06 10:41:20 +00:00
}
?>
2014-07-07 15:45:08 +00:00
2016-05-03 14:22:49 +00:00
< option value = " regenerate_download_permissions " >< ? php _e ( 'Regenerate download permissions' , 'woocommerce' ); ?> </option>
2014-07-11 18:38:23 +00:00
2016-08-27 04:23:02 +00:00
< ? php foreach ( apply_filters ( 'woocommerce_order_actions' , array () ) as $action => $title ) { ?>
2013-08-06 10:41:20 +00:00
< option value = " <?php echo $action ; ?> " >< ? php echo $title ; ?> </option>
< ? php } ?>
</ select >
2016-11-04 15:40:15 +00:00
< button class = " button wc-reload " >< span >< ? php _e ( 'Apply' , 'woocommerce' ); ?> </span></button>
2013-08-06 10:41:20 +00:00
</ li >
< li class = " wide " >
< div id = " delete-action " >< ? php
2014-08-31 07:18:21 +00:00
2014-11-19 23:36:47 +00:00
if ( current_user_can ( 'delete_post' , $post -> ID ) ) {
2014-08-31 07:18:21 +00:00
2014-07-04 14:20:29 +00:00
if ( ! EMPTY_TRASH_DAYS ) {
2016-10-12 10:16:30 +00:00
$delete_text = __ ( 'Delete permanently' , 'woocommerce' );
2014-07-04 14:20:29 +00:00
} else {
2016-10-12 10:16:30 +00:00
$delete_text = __ ( 'Move to trash' , 'woocommerce' );
2014-07-04 14:20:29 +00:00
}
2013-08-06 10:41:20 +00:00
?> <a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo $delete_text; ?></a><?php
}
?> </div>
2016-10-12 10:16:30 +00:00
< 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 ) ); ?> " />
2013-08-06 10:41:20 +00:00
</ li >
< ? php do_action ( 'woocommerce_order_actions_end' , $post -> ID ); ?>
</ ul >
< ? php
}
/**
2015-11-03 12:28:01 +00:00
* Save meta box data .
2016-01-04 21:31:36 +00:00
*
* @ param int $post_id
* @ param WP_Post $post
2013-08-06 10:41:20 +00:00
*/
public static function save ( $post_id , $post ) {
2016-05-03 14:22:49 +00:00
global $wpdb ;
2014-08-31 07:18:21 +00:00
2013-08-06 10:41:20 +00:00
// Order data saved, now get it so we can manipulate status
2014-08-15 12:29:21 +00:00
$order = wc_get_order ( $post_id );
2013-08-06 10:41:20 +00:00
// Handle button actions
if ( ! empty ( $_POST [ 'wc_order_action' ] ) ) {
2013-11-25 13:34:21 +00:00
$action = wc_clean ( $_POST [ 'wc_order_action' ] );
2013-08-06 10:41:20 +00:00
if ( strstr ( $action , 'send_email_' ) ) {
2017-01-23 20:40:36 +00:00
// Switch back to the site locale.
if ( function_exists ( 'switch_to_locale' ) ) {
switch_to_locale ( get_locale () );
}
2013-08-06 10:41:20 +00:00
do_action ( 'woocommerce_before_resend_order_emails' , $order );
2017-01-23 20:40:36 +00:00
// Ensure gateways are loaded in case they need to insert data into the emails.
2014-01-28 12:36:20 +00:00
WC () -> payment_gateways ();
WC () -> shipping ();
2017-01-23 20:40:36 +00:00
// Load mailer.
2013-08-22 11:25:32 +00:00
$mailer = WC () -> mailer ();
2013-08-06 10:41:20 +00:00
$email_to_send = str_replace ( 'send_email_' , '' , $action );
$mails = $mailer -> get_emails ();
if ( ! empty ( $mails ) ) {
foreach ( $mails as $mail ) {
if ( $mail -> id == $email_to_send ) {
2017-02-09 22:49:39 +00:00
$mail -> trigger ( $order -> get_id (), $order );
2016-10-29 10:16:03 +00:00
/* translators: %s: email title */
2015-10-01 15:39:27 +00:00
$order -> add_order_note ( sprintf ( __ ( '%s email notification manually sent.' , 'woocommerce' ), $mail -> title ), false , true );
2013-08-06 10:41:20 +00:00
}
}
}
do_action ( 'woocommerce_after_resend_order_email' , $order , $email_to_send );
2017-01-23 20:40:36 +00:00
// Restore user locale.
if ( function_exists ( 'restore_current_locale' ) ) {
restore_current_locale ();
}
// Change the post saved message.
2014-10-14 13:18:09 +00:00
add_filter ( 'redirect_post_location' , array ( __CLASS__ , 'set_email_sent_message' ) );
2016-05-03 14:22:49 +00:00
} elseif ( 'regenerate_download_permissions' === $action ) {
2013-09-20 16:01:09 +00:00
2016-11-18 17:13:02 +00:00
$data_store = WC_Data_Store :: load ( 'customer-download' );
$data_store -> delete_by_order_id ( $post_id );
wc_downloadable_product_permissions ( $post_id , true );
2013-09-20 16:01:09 +00:00
2013-08-06 10:41:20 +00:00
} else {
2014-11-30 05:14:22 +00:00
if ( ! did_action ( 'woocommerce_order_action_' . sanitize_title ( $action ) ) ) {
do_action ( 'woocommerce_order_action_' . sanitize_title ( $action ), $order );
}
2013-08-06 10:41:20 +00:00
}
}
}
2014-10-14 13:18:09 +00:00
/**
2015-11-03 12:28:01 +00:00
* Set the correct message ID .
2014-10-14 13:18:09 +00:00
*
2016-01-04 21:31:36 +00:00
* @ param string $location
2014-10-14 13:18:09 +00:00
*
* @ since 2.3 . 0
*
* @ static
*
* @ return string
*/
2014-11-19 23:36:47 +00:00
public static function set_email_sent_message ( $location ) {
2014-10-14 13:18:09 +00:00
return add_query_arg ( 'message' , 11 , $location );
}
2014-07-07 20:11:40 +00:00
}