class-wc-shortcode-order-tracking.php 2.3 KB

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