WooCommerce Sequential Order Numbers - Version 1.2.0

Version Description

  • Added support for the order tracking page
Download this release

Release Info

Developer FoxRunSoftware
Plugin Icon WooCommerce Sequential Order Numbers
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.2 to 1.2.0

readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: FoxRunSoftware
3
  Tags: woocommerce, order number
4
  Requires at least: 3.3
5
  Tested up to: 3.3
6
- Stable tag: 1.1.2
7
 
8
  This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
9
 
@@ -28,6 +28,9 @@ This plugin requires WooCommerce 1.5.3 or greater.
28
 
29
  == Changelog ==
30
 
 
 
 
31
  = 1.1.2 =
32
  * Minor updates due to WooCommerce 1.5.4 release
33
 
3
  Tags: woocommerce, order number
4
  Requires at least: 3.3
5
  Tested up to: 3.3
6
+ Stable tag: 1.2.0
7
 
8
  This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
9
 
28
 
29
  == Changelog ==
30
 
31
+ = 1.2.0 =
32
+ * Added support for the order tracking page
33
+
34
  = 1.1.2 =
35
  * Minor updates due to WooCommerce 1.5.4 release
36
 
woocommerce-sequential-order-numbers.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.foxrunsoftware.net/articles/wordpress/woocommerce-sequent
5
  Description: Provides sequential order numbers for WooCommerce orders
6
  Author: Justin Stern
7
  Author URI: http://www.foxrunsoftware.net
8
- Version: 1.1.2
9
 
10
  Copyright: © 2012 Justin Stern (email : justin@foxrunsoftware.net)
11
  License: GNU General Public License v3.0
@@ -22,7 +22,7 @@ if (is_woocommerce_active()) {
22
  if (!class_exists('WC_Seq_Order_Number')) {
23
 
24
  class WC_Seq_Order_Number {
25
- const VERSION = "1.1.2";
26
  const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
27
 
28
  public function __construct() {
@@ -45,6 +45,10 @@ if (is_woocommerce_active()) {
45
  function woocommerce_loaded() {
46
  global $woocommerce;
47
 
 
 
 
 
48
  if (is_admin()) {
49
  // Override a bunch of admin functionality to support the sequential order numbers on the backend, unfortunately...
50
  remove_action('manage_shop_order_posts_custom_column', 'woocommerce_custom_order_columns', 2);
@@ -61,6 +65,65 @@ if (is_woocommerce_active()) {
61
  }
62
 
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  /**
65
  * Largely unchanged from the WooCommerce original, just one point
66
  * change identified below
@@ -570,6 +633,49 @@ if (is_woocommerce_active()) {
570
  }
571
 
572
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
573
  /**
574
  * Run every time. Used since the activation hook is not executed when updating a plugin
575
  */
@@ -605,5 +711,5 @@ if (is_woocommerce_active()) {
605
  }
606
  }
607
 
608
- new WC_Seq_Order_Number();
609
  }
5
  Description: Provides sequential order numbers for WooCommerce orders
6
  Author: Justin Stern
7
  Author URI: http://www.foxrunsoftware.net
8
+ Version: 1.2.0
9
 
10
  Copyright: © 2012 Justin Stern (email : justin@foxrunsoftware.net)
11
  License: GNU General Public License v3.0
22
  if (!class_exists('WC_Seq_Order_Number')) {
23
 
24
  class WC_Seq_Order_Number {
25
+ const VERSION = "1.2.0";
26
  const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
27
 
28
  public function __construct() {
45
  function woocommerce_loaded() {
46
  global $woocommerce;
47
 
48
+ // remove the order tracking shortcode and use our own.
49
+ remove_shortcode( 'woocommerce_order_tracking', 'get_woocommerce_order_tracking' );
50
+ add_shortcode( 'woocommerce_order_tracking', array( &$this, 'get_woocommerce_order_tracking' ) );
51
+
52
  if (is_admin()) {
53
  // Override a bunch of admin functionality to support the sequential order numbers on the backend, unfortunately...
54
  remove_action('manage_shop_order_posts_custom_column', 'woocommerce_custom_order_columns', 2);
65
  }
66
 
67
 
68
+ /**
69
+ * Order Tracking page shortcode, which we hijack and replace with
70
+ * our own order_number-friendly version
71
+ */
72
+ public function get_woocommerce_order_tracking( $atts ) {
73
+ global $woocommerce;
74
+ return $woocommerce->shortcode_wrapper( array( &$this, 'woocommerce_order_tracking' ), $atts );
75
+ }
76
+
77
+
78
+ /**
79
+ * Order Tracking page shortcode, largely unchanged from the original
80
+ * this one just searches by order_number
81
+ */
82
+ public function woocommerce_order_tracking( $atts ) {
83
+ global $woocommerce;
84
+
85
+ $woocommerce->nocache();
86
+
87
+ extract(shortcode_atts(array(
88
+ ), $atts));
89
+
90
+ global $post;
91
+
92
+ if ($_POST) :
93
+
94
+ $woocommerce->verify_nonce( 'order_tracking' );
95
+
96
+ if (isset($_POST['orderid']) && $_POST['orderid'] > 0) $order_id = (int) $_POST['orderid']; else $order_id = 0;
97
+ if (isset($_POST['order_email']) && $_POST['order_email']) $order_email = trim($_POST['order_email']); else $order_email = '';
98
+
99
+ // try and find the order by order_number
100
+ $order = $this->find_order_by_order_number( $order_id );
101
+
102
+ if ($order->id && $order_email) :
103
+
104
+ if (strtolower($order->billing_email) == strtolower($order_email)) :
105
+
106
+ woocommerce_get_template( 'order/tracking.php', array(
107
+ 'order' => $order
108
+ ) );
109
+
110
+ return;
111
+
112
+ endif;
113
+
114
+ endif;
115
+
116
+ echo '<p>'.sprintf(__('Sorry, we could not find that order id in our database. <a href="%s">Want to retry?</a>', 'woocommerce'), get_permalink($post->ID)).'</p>';
117
+
118
+ else :
119
+
120
+ woocommerce_get_template( 'order/form-tracking.php' );
121
+
122
+ endif;
123
+
124
+ }
125
+
126
+
127
  /**
128
  * Largely unchanged from the WooCommerce original, just one point
129
  * change identified below
633
  }
634
 
635
 
636
+ /** Helper methods ******************************************************/
637
+
638
+
639
+ /**
640
+ * Search for an order with order_number $order_number
641
+ *
642
+ * @param string $order_number order number to search for
643
+ *
644
+ * @return WC_Order object with $order_number, or null if none is found
645
+ */
646
+ private function find_order_by_order_number( $order_number ) {
647
+ $order = null;
648
+
649
+ // search for the order by custom order number
650
+ $query_args = array(
651
+ 'numberposts' => 1,
652
+ 'meta_key' => '_order_number',
653
+ 'meta_value' => $order_number,
654
+ 'post_type' => 'shop_order',
655
+ 'post_status' => 'publish',
656
+ 'fields' => 'ids'
657
+ );
658
+
659
+ list( $order_id ) = get_posts( $query_args );
660
+
661
+ if ( $order_id !== null ) $order = new WC_Order( $order_id );
662
+
663
+ // if we didn't find the order, then it may be from an order that pre-existed the installation of the sequential order number plugin
664
+ if ( ! $order ) {
665
+ $order = new WC_Order( $order_number );
666
+ if ( isset( $order->order_custom_fields['_order_number'][0] ) ) {
667
+ // _order_number was set, so this is not an old order, it's a new one that just happened to have post_id that matched the searched-for order_number
668
+ $order = null;
669
+ }
670
+ }
671
+
672
+ return $order;
673
+ }
674
+
675
+
676
+ /** Lifecycle methods ******************************************************/
677
+
678
+
679
  /**
680
  * Run every time. Used since the activation hook is not executed when updating a plugin
681
  */
711
  }
712
  }
713
 
714
+ $GLOBALS['wc_seq_order_number'] = new WC_Seq_Order_Number();
715
  }