diff --git a/admin/writepanels/writepanel-order_notes.php b/admin/writepanels/writepanel-order_notes.php new file mode 100644 index 00000000000..ef4929c079d --- /dev/null +++ b/admin/writepanels/writepanel-order_notes.php @@ -0,0 +1,108 @@ + $post->ID, + 'approve' => 'approve', + 'type' => '' + ); + + $notes = get_comments( $args ); + + echo ''; + ?> +
+

+

+ + + +
+ + – Note: if you edit quantities or remove items from the order you will need to manually change the item\'s stock levels.', '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' ); diff --git a/assets/css/admin.css b/assets/css/admin.css index 38b995cd8e9..db6f6c32392 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -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;} diff --git a/assets/css/admin.less b/assets/css/admin.less index faf5d7031c3..e9ee7fbbef2 100644 --- a/assets/css/admin.less +++ b/assets/css/admin.less @@ -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 { diff --git a/classes/order.class.php b/classes/order.class.php index 692a83284c4..c7d90d1dbc1 100644 --- a/classes/order.class.php +++ b/classes/order.class.php @@ -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; + + } + } \ No newline at end of file diff --git a/shortcodes/shortcode-my_account.php b/shortcodes/shortcode-my_account.php index dd040877aec..a330b06a9aa 100644 --- a/shortcodes/shortcode-my_account.php +++ b/shortcodes/shortcode-my_account.php @@ -457,8 +457,23 @@ function woocommerce_view_order() { echo sprintf( __('. Order status: %s', 'woothemes'), $order->status ); echo '.

'; - ?> + + get_customer_order_notes(); + if ($notes) : + ?> +

+ + + +

diff --git a/shortcodes/shortcode-order_tracking.php b/shortcodes/shortcode-order_tracking.php index 9d8a4ebe587..f21c3e865eb 100644 --- a/shortcodes/shortcode-order_tracking.php +++ b/shortcodes/shortcode-order_tracking.php @@ -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 '.

'; - ?> + + get_customer_order_notes(); + if ($notes) : + ?> +

+ + +

diff --git a/woocommerce_actions.php b/woocommerce_actions.php index b6e26916d3e..c45bf8f309e 100644 --- a/woocommerce_actions.php +++ b/woocommerce_actions.php @@ -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 '
  • '; + echo wpautop(wptexturize($note)); + echo '

    '. sprintf(__('added %s ago', 'woothemes'), human_time_diff(strtotime('NOW'))) .' - '.__('Delete note', 'woothemes').'

    '; + echo '
  • '; + + 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 */