WC_Correios_Admin_Orders

Correios orders.

Defined (1)

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

/includes/admin/class-wc-correios-admin-orders.php  
  1. class WC_Correios_Admin_Orders { 
  2.  
  3. /** 
  4. * Initialize the order actions. 
  5. */ 
  6. public function __construct() { 
  7. add_action( 'add_meta_boxes', array( $this, 'register_metabox' ) ); 
  8. add_filter( 'woocommerce_resend_order_emails_available', array( $this, 'resend_tracking_code_email' ) ); 
  9. add_action( 'wp_ajax_woocommerce_correios_add_tracking_code', array( $this, 'ajax_add_tracking_code' ) ); 
  10. add_action( 'wp_ajax_woocommerce_correios_remove_tracking_code', array( $this, 'ajax_remove_tracking_code' ) ); 
  11.  
  12. /** 
  13. * Register tracking code metabox. 
  14. */ 
  15. public function register_metabox() { 
  16. add_meta_box( 
  17. 'wc_correios',  
  18. 'Correios',  
  19. array( $this, 'metabox_content' ),  
  20. 'shop_order',  
  21. 'side',  
  22. 'default' 
  23. ); 
  24.  
  25. /** 
  26. * Tracking code metabox content. 
  27. * @param WC_Post $post Post data. 
  28. */ 
  29. public function metabox_content( $post ) { 
  30. $tracking_codes = wc_correios_get_tracking_codes( $post->ID ); 
  31.  
  32. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  33. wp_enqueue_style( 'woocommerce-correios-orders-admin', plugins_url( 'assets/css/admin/orders' . $suffix . '.css', WC_Correios::get_main_file() ), array(), WC_Correios::VERSION ); 
  34. wp_enqueue_script( 'woocommerce-correios-orders-admin', plugins_url( 'assets/js/admin/orders' . $suffix . '.js', WC_Correios::get_main_file() ), array( 'jquery', 'jquery-blockui', 'wp-util' ), WC_Correios::VERSION, true ); 
  35. wp_localize_script( 
  36. 'woocommerce-correios-orders-admin',  
  37. 'WCCorreiosAdminOrdersParams',  
  38. array( 
  39. 'order_id' => $post->ID,  
  40. 'i18n' => array( 
  41. 'removeQuestion' => esc_js( __( 'Are you sure you want to remove this tracking code?', 'woocommerce-correios' ) ),  
  42. ),  
  43. 'nonces' => array( 
  44. 'add' => wp_create_nonce( 'woocommerce-correios-add-tracking-code' ),  
  45. 'remove' => wp_create_nonce( 'woocommerce-correios-remove-tracking-code' ),  
  46. ),  
  47. ); 
  48.  
  49. include_once dirname( __FILE__ ) . '/views/html-meta-box-tracking-code.php'; 
  50.  
  51. /** 
  52. * Include option to resend the tracking code email. 
  53. * @param array $emails List of emails. 
  54. * @return array 
  55. */ 
  56. public function resend_tracking_code_email( $emails ) { 
  57. $emails[] = 'correios_tracking'; 
  58.  
  59. return $emails; 
  60.  
  61. /** 
  62. * Ajax - Add tracking code. 
  63. */ 
  64. public function ajax_add_tracking_code() { 
  65. check_ajax_referer( 'woocommerce-correios-add-tracking-code', 'security' ); 
  66.  
  67. $args = filter_input_array( INPUT_POST, array( 
  68. 'order_id' => FILTER_SANITIZE_NUMBER_INT,  
  69. 'tracking_code' => FILTER_SANITIZE_STRING,  
  70. ) ); 
  71.  
  72. $order = wc_get_order( $args['order_id'] ); 
  73.  
  74. wc_correios_update_tracking_code( $order, $args['tracking_code'] ); 
  75.  
  76. $tracking_codes = wc_correios_get_tracking_codes( $order ); 
  77.  
  78. wp_send_json_success( $tracking_codes ); 
  79.  
  80. /** 
  81. * Ajax - Remove tracking code. 
  82. */ 
  83. public function ajax_remove_tracking_code() { 
  84. check_ajax_referer( 'woocommerce-correios-remove-tracking-code', 'security' ); 
  85.  
  86. $args = filter_input_array( INPUT_POST, array( 
  87. 'order_id' => FILTER_SANITIZE_NUMBER_INT,  
  88. 'tracking_code' => FILTER_SANITIZE_STRING,  
  89. ) ); 
  90.  
  91. wc_correios_update_tracking_code( $args['order_id'], $args['tracking_code'], true ); 
  92.  
  93. wp_send_json_success();