/** * Updates status of order * * @param string $new_status Status to change the order to. No internal wc- prefix is required. * @param string $note (default: '') Optional note to add */ public function update_status($new_status, $note = '') { $old_status = $this->get_status(); $new_status = 'wc-' === substr($new_status, 0, 3) ? substr($new_status, 3) : $new_status; // Only update if they differ if ($this->id && $new_status !== $old_status) { // Update the order wp_update_post(array('ID' => $this->id, 'post_status' => 'wc-' . $new_status)); $this->post_status = 'wc-' . $new_status; $this->add_order_note(trim($note . ' ' . sprintf(__('Order status changed from %s to %s.', 'woocommerce'), strtolower(wc_get_order_status_label($old_status)), strtolower(wc_get_order_status_label($new_status))))); // Status was changed do_action('woocommerce_order_status_' . $new_status, $this->id); do_action('woocommerce_order_status_' . $old_status . '_to_' . $new_status, $this->id); do_action('woocommerce_order_status_changed', $this->id, $old_status, $new_status); switch ($new_status) { case 'completed': // Record the sales $this->record_product_sales(); // Increase coupon usage counts $this->increase_coupon_usage_counts(); // Record the completed date of the order update_post_meta($this->id, '_completed_date', current_time('mysql')); // Update reports wc_delete_shop_order_transients($this->id); break; case 'processing': case 'on-hold': // Record the sales $this->record_product_sales(); // Increase coupon usage counts $this->increase_coupon_usage_counts(); // Update reports wc_delete_shop_order_transients($this->id); break; case 'cancelled': // If the order is cancelled, restore used coupons $this->decrease_coupon_usage_counts(); // Update reports wc_delete_shop_order_transients($this->id); break; } } }
/** * Output custom columns for coupons * @param string $column */ public function render_shop_order_columns($column) { global $post, $woocommerce, $the_order; if (empty($the_order) || $the_order->id != $post->ID) { $the_order = wc_get_order($post->ID); } switch ($column) { case 'order_status': printf('<mark class="%s tips" data-tip="%s">%s</mark>', sanitize_title($the_order->get_status()), wc_get_order_status_label($the_order->get_status()), wc_get_order_status_name($the_order->get_status())); break; case 'order_date': if ('0000-00-00 00:00:00' == $post->post_date) { $t_time = $h_time = __('Unpublished', 'woocommerce'); } else { $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post); $gmt_time = strtotime($post->post_date_gmt . ' UTC'); $time_diff = current_time('timestamp', 1) - $gmt_time; $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post); } echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>'; break; case 'customer_message': if ($the_order->customer_message) { echo '<span class="note-on tips" data-tip="' . esc_attr($the_order->customer_message) . '">' . __('Yes', 'woocommerce') . '</span>'; } else { echo '<span class="na">–</span>'; } break; case 'order_items': echo '<a href="#" class="show_order_items">' . apply_filters('woocommerce_admin_order_item_count', sprintf(_n('%d item', '%d items', $the_order->get_item_count(), 'woocommerce'), $the_order->get_item_count()), $the_order) . '</a>'; if (sizeof($the_order->get_items()) > 0) { echo '<table class="order_items" cellspacing="0">'; foreach ($the_order->get_items() as $item) { $_product = apply_filters('woocommerce_order_item_product', $the_order->get_product_from_item($item), $item); $item_meta = new WC_Order_Item_Meta($item['item_meta']); $item_meta_html = $item_meta->display(true, true); ?> <tr class="<?php echo apply_filters('woocommerce_admin_order_item_class', '', $item); ?> "> <td class="qty"><?php echo absint($item['qty']); ?> </td> <td class="name"> <?php if (wc_product_sku_enabled() && $_product && $_product->get_sku()) { echo $_product->get_sku() . ' - '; } echo apply_filters('woocommerce_order_item_name', $item['name'], $item); ?> <?php if ($item_meta_html) { ?> <a class="tips" href="#" data-tip="<?php echo esc_attr($item_meta_html); ?> ">[?]</a> <?php } ?> </td> </tr> <?php } echo '</table>'; } else { echo '–'; } break; case 'shipping_address': if ($the_order->get_formatted_shipping_address()) { echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($the_order->get_shipping_address()) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $the_order->get_formatted_shipping_address())) . '</a>'; } else { echo '–'; } if ($the_order->get_shipping_method()) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->get_shipping_method()) . '</small>'; } break; case 'order_notes': if ($post->comment_count) { // check the status of the post $post->post_status !== 'trash' ? $status = '' : ($status = 'post-trashed'); $latest_notes = get_comments(array('post_id' => $post->ID, 'number' => 1, 'status' => $status)); $latest_note = current($latest_notes); if ($post->comment_count == 1) { echo '<span class="note-on tips" data-tip="' . esc_attr($latest_note->comment_content) . '">' . __('Yes', 'woocommerce') . '</span>'; } else { $note_tip = isset($latest_note->comment_content) ? esc_attr($latest_note->comment_content . '<small style="display:block">' . sprintf(_n('plus %d other note', 'plus %d other notes', $post->comment_count - 1, 'woocommerce'), $post->comment_count - 1) . '</small>') : sprintf(_n('%d note', '%d notes', $post->comment_count, 'woocommerce'), $post->comment_count); echo '<span class="note-on tips" data-tip="' . $note_tip . '">' . __('Yes', 'woocommerce') . '</span>'; } } else { echo '<span class="na">–</span>'; } break; case 'order_total': echo esc_html(strip_tags($the_order->get_formatted_order_total())); if ($the_order->payment_method_title) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->payment_method_title) . '</small>'; } break; case 'order_title': $customer_tip = ''; if ($address = $the_order->get_formatted_billing_address()) { $customer_tip .= __('Billing:', 'woocommerce') . ' ' . $address . '<br/><br/>'; } if ($the_order->billing_phone) { $customer_tip .= __('Tel:', 'woocommerce') . ' ' . $the_order->billing_phone; } echo '<div class="tips" data-tip="' . esc_attr($customer_tip) . '">'; if ($the_order->user_id) { $user_info = get_userdata($the_order->user_id); } if (!empty($user_info)) { $username = '******' . absint($user_info->ID) . '">'; if ($user_info->first_name || $user_info->last_name) { $username .= esc_html(ucfirst($user_info->first_name) . ' ' . ucfirst($user_info->last_name)); } else { $username .= esc_html(ucfirst($user_info->display_name)); } $username .= '</a>'; } else { if ($the_order->billing_first_name || $the_order->billing_last_name) { $username = trim($the_order->billing_first_name . ' ' . $the_order->billing_last_name); } else { $username = __('Guest', 'woocommerce'); } } printf(__('%s by %s', 'woocommerce'), '<a href="' . admin_url('post.php?post=' . absint($post->ID) . '&action=edit') . '"><strong>' . esc_attr($the_order->get_order_number()) . '</strong></a>', $username); if ($the_order->billing_email) { echo '<small class="meta email"><a href="' . esc_url('mailto:' . $the_order->billing_email) . '">' . esc_html($the_order->billing_email) . '</a></small>'; } echo '</div>'; break; case 'order_actions': ?> <p> <?php do_action('woocommerce_admin_order_actions_start', $the_order); $actions = array(); if ($the_order->has_status(array('pending', 'on-hold'))) { $actions['processing'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_processing&order_id=' . $post->ID), 'woocommerce-mark-order-processing'), 'name' => __('Processing', 'woocommerce'), 'action' => "processing"); } if ($the_order->has_status(array('pending', 'on-hold', 'processing'))) { $actions['complete'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_complete&order_id=' . $post->ID), 'woocommerce-mark-order-complete'), 'name' => __('Complete', 'woocommerce'), 'action' => "complete"); } $actions['view'] = array('url' => admin_url('post.php?post=' . $post->ID . '&action=edit'), 'name' => __('View', 'woocommerce'), 'action' => "view"); $actions = apply_filters('woocommerce_admin_order_actions', $actions, $the_order); foreach ($actions as $action) { printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name'])); } do_action('woocommerce_admin_order_actions_end', $the_order); ?> </p><?php break; } }
</td> <td class="order-date"> <time datetime="<?php echo date('Y-m-d', strtotime($order->order_date)); ?> " title="<?php echo esc_attr(strtotime($order->order_date)); ?> "><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?> </time> </td> <td class="order-status" style="text-align:left; white-space:nowrap;"> <?php echo wc_get_order_status_label($order->get_status()); ?> </td> <td class="order-total"> <?php echo sprintf(_n('%s for %s item', '%s for %s items', $item_count, 'woocommerce'), $order->get_formatted_order_total(), $item_count); ?> </td> <td class="order-actions"> <?php $actions = array(); if (in_array($order->get_status(), apply_filters('woocommerce_valid_order_statuses_for_payment', array('pending', 'failed'), $order))) { $actions['pay'] = array('url' => $order->get_checkout_payment_url(), 'name' => __('Pay', 'woocommerce')); } if (in_array($order->get_status(), apply_filters('woocommerce_valid_order_statuses_for_cancel', array('pending', 'failed'), $order))) { $actions['cancel'] = array('url' => $order->get_cancel_order_url(get_permalink(wc_get_page_id('myaccount'))), 'name' => __('Cancel', 'woocommerce'));
* * @author WooThemes * @package WooCommerce/Templates * @version 2.2.0 */ if (!defined('ABSPATH')) { exit; } ?> <?php wc_print_notices(); ?> <p class="order-info"><?php printf(__('Order <mark class="order-number">%s</mark> was placed on <mark class="order-date">%s</mark> and is currently <mark class="order-status">%s</mark>.', 'woocommerce'), $order->get_order_number(), date_i18n(get_option('date_format'), strtotime($order->order_date)), wc_get_order_status_label($order->get_status())); ?> </p> <?php if ($notes = $order->get_customer_order_notes()) { ?> <h2><?php _e('Order Updates', 'woocommerce'); ?> </h2> <ol class="commentlist notes"> <?php foreach ($notes as $note) { ?> <li class="comment note">