Нет описания

class-wc-meta-box-order-actions.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. if ( ! defined( 'ABSPATH' ) ) {
  13. exit; // Exit if accessed directly.
  14. }
  15. /**
  16. * WC_Meta_Box_Order_Actions Class.
  17. */
  18. class WC_Meta_Box_Order_Actions {
  19. /**
  20. * Output the metabox.
  21. *
  22. * @param WP_Post $post Post object.
  23. */
  24. public static function output( $post ) {
  25. global $theorder;
  26. // 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.
  27. if ( ! is_object( $theorder ) ) {
  28. $theorder = wc_get_order( $post->ID );
  29. }
  30. $order_actions = apply_filters(
  31. 'woocommerce_order_actions',
  32. array(
  33. 'send_order_details' => __( 'Email invoice / order details to customer', 'woocommerce' ),
  34. 'send_order_details_admin' => __( 'Resend new order notification', 'woocommerce' ),
  35. 'regenerate_download_permissions' => __( 'Regenerate download permissions', 'woocommerce' ),
  36. )
  37. );
  38. ?>
  39. <ul class="order_actions submitbox">
  40. <?php do_action( 'woocommerce_order_actions_start', $post->ID ); ?>
  41. <li class="wide" id="actions">
  42. <select name="wc_order_action">
  43. <option value=""><?php esc_html_e( 'Choose an action...', 'woocommerce' ); ?></option>
  44. <?php foreach ( $order_actions as $action => $title ) { ?>
  45. <option value="<?php echo esc_attr( $action ); ?>"><?php echo esc_html( $title ); ?></option>
  46. <?php } ?>
  47. </select>
  48. <button class="button wc-reload"><span><?php esc_html_e( 'Apply', 'woocommerce' ); ?></span></button>
  49. </li>
  50. <li class="wide">
  51. <div id="delete-action">
  52. <?php
  53. if ( current_user_can( 'delete_post', $post->ID ) ) {
  54. if ( ! EMPTY_TRASH_DAYS ) {
  55. $delete_text = __( 'Delete permanently', 'woocommerce' );
  56. } else {
  57. $delete_text = __( 'Move to Trash', 'woocommerce' );
  58. }
  59. ?>
  60. <a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo esc_html( $delete_text ); ?></a>
  61. <?php
  62. }
  63. ?>
  64. </div>
  65. <button 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' ); ?>"><?php echo 'auto-draft' === $post->post_status ? esc_html__( 'Create', 'woocommerce' ) : esc_html__( 'Update', 'woocommerce' ); ?></button>
  66. </li>
  67. <?php do_action( 'woocommerce_order_actions_end', $post->ID ); ?>
  68. </ul>
  69. <?php
  70. }
  71. /**
  72. * Save meta box data.
  73. *
  74. * @param int $post_id Post ID.
  75. * @param WP_Post $post Post Object.
  76. */
  77. public static function save( $post_id, $post ) {
  78. // Order data saved, now get it so we can manipulate status.
  79. $order = wc_get_order( $post_id );
  80. // Handle button actions.
  81. if ( ! empty( $_POST['wc_order_action'] ) ) { // @codingStandardsIgnoreLine
  82. $action = wc_clean( wp_unslash( $_POST['wc_order_action'] ) ); // @codingStandardsIgnoreLine
  83. if ( 'send_order_details' === $action ) {
  84. do_action( 'woocommerce_before_resend_order_emails', $order, 'customer_invoice' );
  85. // Send the customer invoice email.
  86. WC()->payment_gateways();
  87. WC()->shipping();
  88. WC()->mailer()->customer_invoice( $order );
  89. // Note the event.
  90. $order->add_order_note( __( 'Order details manually sent to customer.', 'woocommerce' ), false, true );
  91. do_action( 'woocommerce_after_resend_order_email', $order, 'customer_invoice' );
  92. // Change the post saved message.
  93. add_filter( 'redirect_post_location', array( __CLASS__, 'set_email_sent_message' ) );
  94. } elseif ( 'send_order_details_admin' === $action ) {
  95. do_action( 'woocommerce_before_resend_order_emails', $order, 'new_order' );
  96. WC()->payment_gateways();
  97. WC()->shipping();
  98. add_filter( 'woocommerce_new_order_email_allows_resend', '__return_true' );
  99. WC()->mailer()->emails['WC_Email_New_Order']->trigger( $order->get_id(), $order, true );
  100. remove_filter( 'woocommerce_new_order_email_allows_resend', '__return_true' );
  101. do_action( 'woocommerce_after_resend_order_email', $order, 'new_order' );
  102. // Change the post saved message.
  103. add_filter( 'redirect_post_location', array( __CLASS__, 'set_email_sent_message' ) );
  104. } elseif ( 'regenerate_download_permissions' === $action ) {
  105. $data_store = WC_Data_Store::load( 'customer-download' );
  106. $data_store->delete_by_order_id( $post_id );
  107. wc_downloadable_product_permissions( $post_id, true );
  108. } else {
  109. if ( ! did_action( 'woocommerce_order_action_' . sanitize_title( $action ) ) ) {
  110. do_action( 'woocommerce_order_action_' . sanitize_title( $action ), $order );
  111. }
  112. }
  113. }
  114. }
  115. /**
  116. * Set the correct message ID.
  117. *
  118. * @param string $location Location.
  119. * @since 2.3.0
  120. * @static
  121. * @return string
  122. */
  123. public static function set_email_sent_message( $location ) {
  124. return add_query_arg( 'message', 11, $location );
  125. }
  126. }