PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/post-types/writepanels/writepanel-order_notes.php

https://github.com/CammoKing/woocommerce
PHP | 120 lines | 77 code | 27 blank | 16 comment | 5 complexity | 7dfb15d6a4a9789eb7008f40f3f79221 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Order Notes
  4. *
  5. * Functions for displaying order comments in admin.
  6. *
  7. * @author WooThemes
  8. * @category Admin
  9. * @package WooCommerce/Admin/WritePanels
  10. * @version 1.7.0
  11. */
  12. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  13. /**
  14. * Display the order notes meta box.
  15. *
  16. * @access public
  17. * @return void
  18. */
  19. function woocommerce_order_notes_meta_box() {
  20. global $woocommerce, $post;
  21. $args = array(
  22. 'post_id' => $post->ID,
  23. 'approve' => 'approve',
  24. 'type' => 'order_note'
  25. );
  26. $notes = get_comments( $args );
  27. echo '<ul class="order_notes">';
  28. if ( $notes ) {
  29. foreach( $notes as $note ) {
  30. $note_classes = get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? array( 'customer-note', 'note' ) : array( 'note' );
  31. ?>
  32. <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo implode( ' ', $note_classes ); ?>">
  33. <div class="note_content">
  34. <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
  35. </div>
  36. <p class="meta">
  37. <?php printf( __( 'added %s ago', 'woocommerce' ), human_time_diff( strtotime( $note->comment_date_gmt ), current_time( 'timestamp', 1 ) ) ); ?> <a href="#" class="delete_note"><?php _e( 'Delete note', 'woocommerce' ); ?></a>
  38. </p>
  39. </li>
  40. <?php
  41. }
  42. } else {
  43. echo '<li>' . __( 'There are no notes for this order yet.', 'woocommerce' ) . '</li>';
  44. }
  45. echo '</ul>';
  46. ?>
  47. <div class="add_note">
  48. <h4><?php _e( 'Add note', 'woocommerce' ); ?> <img class="help_tip" data-tip='<?php esc_attr_e( 'Add a note for your reference, or add a customer note (the user will be notified).', 'woocommerce' ); ?>' src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png" /></h4>
  49. <p>
  50. <textarea type="text" name="order_note" id="add_order_note" class="input-text" cols="20" rows="5"></textarea>
  51. </p>
  52. <p>
  53. <select name="order_note_type" id="order_note_type">
  54. <option value="customer"><?php _e( 'Customer note', 'woocommerce' ); ?></option>
  55. <option value=""><?php _e( 'Private note', 'woocommerce' ); ?></option>
  56. </select>
  57. <a href="#" class="add_note button"><?php _e( 'Add', 'woocommerce' ); ?></a>
  58. </p>
  59. </div>
  60. <script type="text/javascript">
  61. jQuery('a.add_note').click(function(){
  62. if (!jQuery('textarea#add_order_note').val()) return;
  63. jQuery('#woocommerce-order-notes').block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
  64. var data = {
  65. action: 'woocommerce_add_order_note',
  66. post_id: '<?php echo $post->ID; ?>',
  67. note: jQuery('textarea#add_order_note').val(),
  68. note_type: jQuery('select#order_note_type').val(),
  69. security: '<?php echo wp_create_nonce("add-order-note"); ?>'
  70. };
  71. jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
  72. jQuery('ul.order_notes').prepend( response );
  73. jQuery('#woocommerce-order-notes').unblock();
  74. jQuery('#add_order_note').val('');
  75. });
  76. return false;
  77. });
  78. jQuery('a.delete_note').live('click', function(){
  79. var note = jQuery(this).closest('li.note');
  80. jQuery(note).block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
  81. var data = {
  82. action: 'woocommerce_delete_order_note',
  83. note_id: jQuery(note).attr('rel'),
  84. security: '<?php echo wp_create_nonce("delete-order-note"); ?>'
  85. };
  86. jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
  87. jQuery(note).remove();
  88. });
  89. return false;
  90. });
  91. </script>
  92. <?php
  93. }