class-wc-shortcode-cart.php
6 years ago
class-wc-shortcode-checkout.php
5 years ago
class-wc-shortcode-my-account.php
6 years ago
class-wc-shortcode-order-tracking.php
6 years ago
class-wc-shortcode-products.php
5 years ago
class-wc-shortcode-order-tracking.php
72 lines
| 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 | * @package WooCommerce/Shortcodes/Order_Tracking |
| 8 | * @version 3.0.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * Shortcode order tracking class. |
| 15 | */ |
| 16 | class WC_Shortcode_Order_Tracking { |
| 17 | |
| 18 | /** |
| 19 | * Get the shortcode content. |
| 20 | * |
| 21 | * @param array $atts Shortcode attributes. |
| 22 | * @return string |
| 23 | */ |
| 24 | public static function get( $atts ) { |
| 25 | return WC_Shortcodes::shortcode_wrapper( array( __CLASS__, 'output' ), $atts ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Output the shortcode. |
| 30 | * |
| 31 | * @param array $atts Shortcode attributes. |
| 32 | */ |
| 33 | public static function output( $atts ) { |
| 34 | // Check cart class is loaded or abort. |
| 35 | if ( is_null( WC()->cart ) ) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $atts = shortcode_atts( array(), $atts, 'woocommerce_order_tracking' ); |
| 40 | $nonce_value = wc_get_var( $_REQUEST['woocommerce-order-tracking-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine. |
| 41 | |
| 42 | if ( isset( $_REQUEST['orderid'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-order_tracking' ) ) { // WPCS: input var ok. |
| 43 | |
| 44 | $order_id = empty( $_REQUEST['orderid'] ) ? 0 : ltrim( wc_clean( wp_unslash( $_REQUEST['orderid'] ) ), '#' ); // WPCS: input var ok. |
| 45 | $order_email = empty( $_REQUEST['order_email'] ) ? '' : sanitize_email( wp_unslash( $_REQUEST['order_email'] ) ); // WPCS: input var ok. |
| 46 | |
| 47 | if ( ! $order_id ) { |
| 48 | wc_print_notice( __( 'Please enter a valid order ID', 'woocommerce' ), 'error' ); |
| 49 | } elseif ( ! $order_email ) { |
| 50 | wc_print_notice( __( 'Please enter a valid email address', 'woocommerce' ), 'error' ); |
| 51 | } else { |
| 52 | $order = wc_get_order( apply_filters( 'woocommerce_shortcode_order_tracking_order_id', $order_id ) ); |
| 53 | |
| 54 | if ( $order && $order->get_id() && strtolower( $order->get_billing_email() ) === strtolower( $order_email ) ) { |
| 55 | do_action( 'woocommerce_track_order', $order->get_id() ); |
| 56 | wc_get_template( |
| 57 | 'order/tracking.php', |
| 58 | array( |
| 59 | 'order' => $order, |
| 60 | ) |
| 61 | ); |
| 62 | return; |
| 63 | } else { |
| 64 | wc_print_notice( __( 'Sorry, the order could not be found. Please contact us if you are having difficulty finding your order details.', 'woocommerce' ), 'error' ); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | wc_get_template( 'order/form-tracking.php' ); |
| 70 | } |
| 71 | } |
| 72 |