Order notes section and front-end display

This commit is contained in:
Mike Jolley 2011-09-23 15:22:21 +01:00
parent d0bc083219
commit 9ab2193c7a
8 changed files with 313 additions and 35 deletions

View File

@ -0,0 +1,108 @@
<?php
/**
* Order Notes
*
* Functions for displaying order comments in admin
*
* @author WooThemes
* @category Admin Write Panels
* @package WooCommerce
*/
/**
* Order notes meta box
*/
function woocommerce_order_notes_meta_box() {
global $woocommerce, $post;
$args = array(
'post_id' => $post->ID,
'approve' => 'approve',
'type' => ''
);
$notes = get_comments( $args );
echo '<ul class="order_notes">';
if ($notes) :
foreach($notes as $note) :
$customer_note = get_comment_meta($note->comment_ID, 'is_customer_note', true);
echo '<li rel="'.$note->comment_ID.'" class="note ';
if ($customer_note) echo 'customer-note';
echo '"><div class="note_content">';
echo wpautop(wptexturize($note->comment_content));
echo '</div><p class="meta">'. sprintf(__('added %s ago', 'woothemes'), human_time_diff(strtotime($note->comment_date))) .' - <a href="#" class="delete_note">'.__('Delete note', 'woothemes').'</a></p>';
echo '</li>';
endforeach;
else :
echo '<li>' . __('There are no notes for this order yet.', 'woothemes') . '</li>';
endif;
echo '</ul>';
?>
<div class="add_note">
<h4><?php _e('Add note', 'woothemes'); ?></h4>
<p><?php _e('Add a note for your reference, or add a customer note that the customer can view on their view order and track order pages.', 'woothemes'); ?></p>
<input type="text" name="order_note" id="add_order_note" class="input-text" />
<select name="order_note_type" id="order_note_type">
<option value="customer"><?php _e('Customer note', 'woothemes'); ?></option>
<option value=""><?php _e('Private note', 'woothemes'); ?></option>
</select>
<a href="#" class="add_note button"><?php _e('Add', 'woothemes'); ?></a>
</div>
<script type="text/javascript">
jQuery('a.add_note').click(function(){
if (!jQuery('input#add_order_note').val()) return;
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 } });
var data = {
action: 'woocommerce_add_order_note',
post_id: '<?php echo $post->ID; ?>',
note: jQuery('input#add_order_note').val(),
note_type: jQuery('select#order_note_type').val(),
security: '<?php echo wp_create_nonce("add-order-note"); ?>'
};
jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
jQuery('ul.order_notes').prepend( response );
jQuery('#woocommerce-order-notes').unblock();
jQuery('#add_order_note').val('');
});
return false;
});
jQuery('a.delete_note').live('click', function(){
var note = jQuery(this).closest('li.note');
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 } });
var data = {
action: 'woocommerce_delete_order_note',
note_id: jQuery(note).attr('rel'),
security: '<?php echo wp_create_nonce("delete-order-note"); ?>'
};
jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
jQuery(note).remove();
});
return false;
});
</script>
<?php
}

View File

@ -12,6 +12,7 @@
require_once('writepanel-product_data.php');
require_once('writepanel-product-types.php');
require_once('writepanel-order_data.php');
require_once('writepanel-order_notes.php');
require_once('writepanel-coupon_data.php');
/**
@ -29,9 +30,10 @@ function woocommerce_meta_boxes() {
add_meta_box( 'woocommerce-order-data', __('Order Data', 'woothemes'), 'woocommerce_order_data_meta_box', 'shop_order', 'normal', 'high' );
add_meta_box( 'woocommerce-order-items', __('Order Items <small>&ndash; Note: if you edit quantities or remove items from the order you will need to manually change the item\'s stock levels.</small>', 'woothemes'), 'woocommerce_order_items_meta_box', 'shop_order', 'normal', 'high');
add_meta_box( 'woocommerce-order-totals', __('Order Totals', 'woothemes'), 'woocommerce_order_totals_meta_box', 'shop_order', 'side', 'default');
add_meta_box( 'woocommerce-order-notes', __('Order Notes', 'woothemes'), 'woocommerce_order_notes_meta_box', 'shop_order', 'normal', 'default');
add_meta_box( 'woocommerce-order-actions', __('Order Actions', 'woothemes'), 'woocommerce_order_actions_meta_box', 'shop_order', 'side', 'default');
remove_meta_box( 'commentsdiv', 'shop_order' , 'normal' );
remove_meta_box( 'commentstatusdiv', 'shop_order' , 'normal' );
remove_meta_box( 'slugdiv', 'shop_order' , 'normal' );

View File

@ -1,6 +1,5 @@
#toplevel_page_woocommerce .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat 0px -32px !important;}
#toplevel_page_woocommerce .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat 0px -32px !important;}#toplevel_page_woocommerce .wp-menu-image img{display:none;}
#toplevel_page_woocommerce:hover .wp-menu-image,#toplevel_page_woocommerce.wp-has-current-submenu .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat 0px 0px !important;}
#toplevel_page_woocommerce .wp-menu-image img{display:none;}
#menu-posts-product .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -35px -32px !important;}
#menu-posts-product:hover .wp-menu-image,#menu-posts-product.wp-has-current-submenu .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -35px 0px !important;}
#menu-posts-shop_order .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -70px -32px !important;}
@ -60,6 +59,14 @@ ul.subsubsub li.completed a{color:green;}
ul.subsubsub li.onhold a{color:red;}
ul.subsubsub li.cancelled a{color:#dfdfdf;}
ul.subsubsub li.refunded a{color:#ccc;}
ul.order_notes{padding:2px 0 0 0;}ul.order_notes li .note_content{padding:10px;background:#efefef;position:relative;}
ul.order_notes li p.meta{padding:10px;color:#999;font-size:11px;}
ul.order_notes li a.delete_note{color:red;}
ul.order_notes li .note_content:after{content:"";display:block;position:absolute;bottom:-15px;left:30px;width:0;height:0;border-width:15px 15px 0 0;border-style:solid;border-color:#efefef transparent;}
ul.order_notes li.customer-note .note_content{background:#d7cad2;}
ul.order_notes li.customer-note .note_content:after{border-color:#d7cad2 transparent;}
.add_note{border-top:1px solid #ddd;padding:10px;}.add_note h4{margin-top:5px !important;}
.add_note input#add_order_note{width:50%;}
table.wp-list-table .column-thumb{width:66px;text-align:center;white-space:nowrap;}
table.wp-list-table .column-sku,table.wp-list-table .column-product_type,table.wp-list-table .column-product_cat,table.wp-list-table .column-product_tags,table.wp-list-table .column-is_in_stock,table.wp-list-table .column-price,table.wp-list-table .column-product_date,table.wp-list-table .column-featured{width:9%;}
table.wp-list-table img{margin:1px 2px;}

View File

@ -1,31 +1,30 @@
#toplevel_page_woocommerce .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat 0px -32px !important;
#toplevel_page_woocommerce {
.wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat 0px -32px !important;
img {
display: none;
}
}
&:hover .wp-menu-image, &.wp-has-current-submenu .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat 0px 0px !important;
}
}
#toplevel_page_woocommerce:hover .wp-menu-image,
#toplevel_page_woocommerce.wp-has-current-submenu .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat 0px 0px !important;
#menu-posts-product {
.wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat -35px -32px !important;
}
&:hover .wp-menu-image, &.wp-has-current-submenu .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat -35px 0px !important;
}
}
#toplevel_page_woocommerce .wp-menu-image img {
display: none;
#menu-posts-shop_order {
.wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat -70px -32px !important;
}
&:hover .wp-menu-image, &.wp-has-current-submenu .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat -70px 0px !important;
}
}
#menu-posts-product .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat -35px -32px !important;
}
#menu-posts-product:hover .wp-menu-image,
#menu-posts-product.wp-has-current-submenu .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat -35px 0px !important;
}
#menu-posts-shop_order .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat -70px -32px !important;
}
#menu-posts-shop_order:hover .wp-menu-image,
#menu-posts-shop_order.wp-has-current-submenu .wp-menu-image {
background: url(../images/icons/menu_icons.png) no-repeat -70px 0px !important;
}
#icon-woocommerce, .woocommerce_icon, .icon32-posts-product, .icon32-posts-shop_order, .icon32-posts-shop_coupon, .icon32-posts-product_variation {
background-image: url(../images/icons/woocommerce-icons.png) !important;
background-position: -11px -6px;
@ -234,7 +233,6 @@ dl.totals {
float: left;
}
}
.widefat {
.column-order_title {
time {
@ -304,7 +302,6 @@ dl.totals {
}
}
}
ul.subsubsub {
li.pending {
a {
@ -333,6 +330,56 @@ ul.subsubsub {
}
}
/* Order notes */
ul.order_notes {
padding: 2px 0 0 0;
li {
.note_content {
padding: 10px;
background: #efefef;
position: relative;
}
p.meta {
padding: 10px;
color: #999;
font-size: 11px;
}
a.delete_note {
color: red
}
.note_content:after {
content: "";
display: block;
position: absolute;
bottom: -15px;
left: 30px;
width: 0;
height: 0;
border-width: 15px 15px 0 0;
border-style: solid;
border-color: #efefef transparent;
}
}
li.customer-note {
.note_content {
background: #d7cad2;
}
.note_content:after {
border-color: #d7cad2 transparent;
}
}
}
.add_note {
border-top: 1px solid #ddd;
padding: 10px;
h4 {
margin-top: 5px !important;
}
input#add_order_note {
width: 50%;
}
}
/* Product list */
table.wp-list-table {
.column-thumb {

View File

@ -306,9 +306,9 @@ class woocommerce_order {
* Adds a note (comment) to the order
*
* @param string $note Note to add
* @param int $private Currently unused
* @param int $is_customer_note Is this a note for the customer?
*/
function add_order_note( $note, $private = 1 ) {
function add_order_note( $note, $is_customer_note = 0 ) {
$comment_post_ID = $this->id;
$comment_author = 'WooCommerce';
@ -328,7 +328,9 @@ class woocommerce_order {
$comment_id = wp_insert_comment( $commentdata );
add_comment_meta($comment_id, 'private', $private);
add_comment_meta($comment_id, 'is_customer_note', $is_customer_note);
return $comment_id;
}
@ -453,4 +455,32 @@ class woocommerce_order {
}
/**
* List order notes (public) for the customer
*/
function get_customer_order_notes() {
$notes = array();
$args = array(
'post_id' => $this->id,
'approve' => 'approve',
'type' => ''
);
remove_filter('comments_clauses', 'woocommerce_exclude_order_comments');
$comments = get_comments( $args );
foreach ($comments as $comment) :
$is_customer_note = get_comment_meta($comment->comment_ID, 'is_customer_note', true);
if ($is_customer_note) $notes[] = $comment;
endforeach;
add_filter('comments_clauses', 'woocommerce_exclude_order_comments');
return (array) $notes;
}
}

View File

@ -457,8 +457,23 @@ function woocommerce_view_order() {
echo sprintf( __('. Order status: <mark>%s</mark>', 'woothemes'), $order->status );
echo '.</p>';
?>
<?php
$notes = $order->get_customer_order_notes();
if ($notes) :
?>
<h2><?php _e('Order Updates', 'woothemes'); ?></h2>
<ul class="notes">
<?php foreach ($notes as $note) : ?>
<li><p><strong><?php echo date_i18n('l jS \of F Y, h:ia', strtotime($note->comment_date)); ?></strong></p><?php echo wpautop(wptexturize($note->comment_content)); ?></li>
<?php endforeach; ?>
</ul>
<?php
endif;
?>
<h2><?php _e('Order Details', 'woothemes'); ?></h2>
<table class="shop_table">
<thead>
<tr>

View File

@ -41,8 +41,22 @@ function woocommerce_order_tracking( $atts ) {
if ($order->status == 'completed') echo __(' and was completed ', 'woothemes').human_time_diff(strtotime($order->completed_date), current_time('timestamp')).__(' ago', 'woothemes');
echo '.</p>';
?>
<?php
$notes = $order->get_customer_order_notes();
if ($notes) :
?>
<h2><?php _e('Order Updates', 'woothemes'); ?></h2>
<ul class="notes">
<?php foreach ($notes as $note) : ?>
<li><p><strong><?php echo date_i18n('l jS \of F Y, h:ia', strtotime($note->comment_date)); ?></strong></p><?php echo wpautop(wptexturize($note->comment_content)); ?></li>
<?php endforeach; ?>
</ul>
<?php
endif;
?>
<h2><?php _e('Order Details', 'woothemes'); ?></h2>
<table class="shop_table">
<thead>

View File

@ -246,6 +246,61 @@ function woocommerce_add_order_item() {
}
/**
* Add order note via ajax
*/
add_action('wp_ajax_woocommerce_add_order_note', 'woocommerce_add_order_note');
function woocommerce_add_order_note() {
global $woocommerce;
check_ajax_referer( 'add-order-note', 'security' );
$post_id = (int) $_POST['post_id'];
$note = strip_tags(woocommerce_clean($_POST['note']));
$note_type = $_POST['note_type'];
$is_customer_note = ($note_type=='customer') ? 1 : 0;
if ($post_id>0) :
$order = &new woocommerce_order( $post_id );
$comment_id = $order->add_order_note( $note, $is_customer_note );
echo '<li rel="'.$comment_id.'" class="note ';
if ($is_customer_note) echo 'customer-note';
echo '"><div class="note_content">';
echo wpautop(wptexturize($note));
echo '</div><p class="meta">'. sprintf(__('added %s ago', 'woothemes'), human_time_diff(strtotime('NOW'))) .' - <a href="#" class="delete_note">'.__('Delete note', 'woothemes').'</a></p>';
echo '</li>';
endif;
// Quit out
die();
}
/**
* Delete order note via ajax
*/
add_action('wp_ajax_woocommerce_delete_order_note', 'woocommerce_delete_order_note');
function woocommerce_delete_order_note() {
global $woocommerce;
check_ajax_referer( 'delete-order-note', 'security' );
$note_id = (int) $_POST['note_id'];
if ($note_id>0) :
wp_delete_comment( $note_id );
endif;
// Quit out
die();
}
/**
* Search for products for upsells/crosssells
*/