1 <?php
 2 /**
 3  * Order Tracking Shortcode
 4  *
 5  * Lets a user see the status of an order by entering their order details.
 6  *
 7  * @author      WooThemes
 8  * @category    Shortcodes
 9  * @package     WooCommerce/Shortcodes/Order_Tracking
10  * @version     2.0.0
11  */
12 
13 class WC_Shortcode_Order_Tracking {
14 
15     /**
16      * Get the shortcode content.
17      *
18      * @access public
19      * @param array $atts
20      * @return string
21      */
22     public static function get( $atts ) {
23         return WC_Shortcodes::shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
24     }
25 
26     /**
27      * Output the shortcode.
28      *
29      * @access public
30      * @param array $atts
31      * @return void
32      */
33     public static function output( $atts ) {
34 
35         // Check cart class is loaded or abort
36         if ( is_null( WC()->cart ) ) {
37             return;
38         }
39 
40         extract(shortcode_atts(array(
41         ), $atts));
42 
43         global $post;
44 
45         if ( ! empty( $_REQUEST['orderid'] ) ) {
46 
47             wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-order_tracking' );
48 
49             $order_id       = empty( $_REQUEST['orderid'] ) ? 0 : esc_attr( $_REQUEST['orderid'] );
50             $order_email    = empty( $_REQUEST['order_email'] ) ? '' : esc_attr( $_REQUEST['order_email']) ;
51 
52             if ( ! $order_id ) {
53 
54                 echo '<p class="woocommerce-error">' . __( 'Please enter a valid order ID', 'woocommerce' ) . '</p>';
55 
56             } elseif ( ! $order_email ) {
57 
58                 echo '<p class="woocommerce-error">' . __( 'Please enter a valid order email', 'woocommerce' ) . '</p>';
59 
60             } else {
61 
62                 $order = new WC_Order( apply_filters( 'woocommerce_shortcode_order_tracking_order_id', $order_id ) );
63 
64                 if ( $order->id && $order_email ) {
65 
66                     if ( strtolower( $order->billing_email ) == strtolower( $order_email ) ) {
67                         do_action( 'woocommerce_track_order', $order->id );
68                         wc_get_template( 'order/tracking.php', array(
69                             'order' => $order
70                         ) );
71 
72                         return;
73                     }
74 
75                 } else {
76 
77                     echo '<p class="woocommerce-error">' . sprintf( __( 'Sorry, we could not find that order id in our database.', 'woocommerce' ), get_permalink($post->ID ) ) . '</p>';
78 
79                 }
80 
81             }
82 
83         }
84 
85         wc_get_template( 'order/form-tracking.php' );
86     }
87 }
WooCommerce API documentation generated by ApiGen 2.8.0