2012-12-31 18:25:09 +00:00
< ? php
/**
* Order Tracking Shortcode
*
* Lets a user see the status of an order by entering their order details .
*
2020-08-05 16:36:24 +00:00
* @ package WooCommerce\Shortcodes\Order_Tracking
2018-03-09 16:15:53 +00:00
* @ version 3.0 . 0
*/
defined ( 'ABSPATH' ) || exit ;
/**
* Shortcode order tracking class .
2012-12-31 18:25:09 +00:00
*/
class WC_Shortcode_Order_Tracking {
/**
* Get the shortcode content .
*
2018-03-09 16:15:53 +00:00
* @ param array $atts Shortcode attributes .
2012-12-31 18:25:09 +00:00
* @ return string
*/
public static function get ( $atts ) {
2013-08-09 16:11:15 +00:00
return WC_Shortcodes :: shortcode_wrapper ( array ( __CLASS__ , 'output' ), $atts );
2012-12-31 18:25:09 +00:00
}
/**
* Output the shortcode .
*
2018-03-09 16:15:53 +00:00
* @ param array $atts Shortcode attributes .
2012-12-31 18:25:09 +00:00
*/
public static function output ( $atts ) {
2018-03-09 16:15:53 +00:00
// Check cart class is loaded or abort.
2014-02-26 15:27:26 +00:00
if ( is_null ( WC () -> cart ) ) {
return ;
}
2018-03-13 14:16:56 +00:00
$atts = shortcode_atts ( array (), $atts , 'woocommerce_order_tracking' );
$nonce_value = wc_get_var ( $_REQUEST [ 'woocommerce-order-tracking-nonce' ], wc_get_var ( $_REQUEST [ '_wpnonce' ], '' ) ); // @codingStandardsIgnoreLine.
2012-12-31 18:25:09 +00:00
2018-03-13 14:16:56 +00:00
if ( isset ( $_REQUEST [ 'orderid' ] ) && wp_verify_nonce ( $nonce_value , 'woocommerce-order_tracking' ) ) { // WPCS: input var ok.
2012-12-31 18:25:09 +00:00
2018-03-09 16:15:53 +00:00
$order_id = empty ( $_REQUEST [ 'orderid' ] ) ? 0 : ltrim ( wc_clean ( wp_unslash ( $_REQUEST [ 'orderid' ] ) ), '#' ); // WPCS: input var ok.
$order_email = empty ( $_REQUEST [ 'order_email' ] ) ? '' : sanitize_email ( wp_unslash ( $_REQUEST [ 'order_email' ] ) ); // WPCS: input var ok.
2012-12-31 18:25:09 +00:00
if ( ! $order_id ) {
2018-04-19 17:26:21 +00:00
wc_print_notice ( __ ( 'Please enter a valid order ID' , 'woocommerce' ), 'error' );
2012-12-31 18:25:09 +00:00
} elseif ( ! $order_email ) {
2018-04-19 17:26:21 +00:00
wc_print_notice ( __ ( 'Please enter a valid email address' , 'woocommerce' ), 'error' );
2012-12-31 18:25:09 +00:00
} else {
2014-08-15 12:29:21 +00:00
$order = wc_get_order ( apply_filters ( 'woocommerce_shortcode_order_tracking_order_id' , $order_id ) );
2012-12-31 18:25:09 +00:00
2017-07-13 13:50:30 +00:00
if ( $order && $order -> get_id () && strtolower ( $order -> get_billing_email () ) === strtolower ( $order_email ) ) {
do_action ( 'woocommerce_track_order' , $order -> get_id () );
2018-03-09 16:15:53 +00:00
wc_get_template (
2019-12-20 18:25:23 +00:00
'order/tracking.php' ,
array (
2018-03-09 16:15:53 +00:00
'order' => $order ,
)
);
2017-07-13 13:50:30 +00:00
return ;
2012-12-31 18:25:09 +00:00
} else {
2018-04-19 17:26:21 +00:00
wc_print_notice ( __ ( 'Sorry, the order could not be found. Please contact us if you are having difficulty finding your order details.' , 'woocommerce' ), 'error' );
2012-12-31 18:25:09 +00:00
}
}
}
2013-11-25 12:45:04 +00:00
wc_get_template ( 'order/form-tracking.php' );
2012-12-31 18:25:09 +00:00
}
2014-09-20 19:33:32 +00:00
}