$order->get_id(), 'key' => $order->get_order_key(), ), $base ); } /** * The order a status request is for, if the key matches. * * @param mixed $order_id Order ID. * @param mixed $key Order key. * @return WC_Order|null */ function sofrah_board_order_for_key( $order_id, $key ) { $order = wc_get_order( absint( $order_id ) ); if ( ! sofrah_board_is_board_order( $order ) || ! is_string( $key ) || '' === $key || ! hash_equals( $order->get_order_key(), $key ) ) { return null; } return $order; } /** * What the diner sees for an order: used by the page and by its refresh. * * @param WC_Order $order Order. * @return array */ function sofrah_board_public_status( WC_Order $order ) { $status = sofrah_board_get_status( $order ); $pickup = (int) $order->get_meta( '_sofrah_board_pickup_at' ); $reason = (string) $order->get_meta( '_sofrah_board_reason' ); $explain = array( 'awaiting' => __( 'The restaurant has not accepted your order yet. This page updates by itself, and we will email you.', 'sofrah-order-board' ), 'accepted' => $pickup ? sprintf( /* translators: %s: time */ __( 'The restaurant has accepted your order. Please collect it at %s.', 'sofrah-order-board' ), wp_date( get_option( 'time_format' ), $pickup ) ) : __( 'The restaurant has accepted your order.', 'sofrah-order-board' ), 'preparing' => $pickup ? sprintf( /* translators: %s: time */ __( 'Your order is being prepared. Please collect it at %s.', 'sofrah-order-board' ), wp_date( get_option( 'time_format' ), $pickup ) ) : __( 'Your order is being prepared.', 'sofrah-order-board' ), 'ready' => __( 'Your order is ready. Please collect it and pay at the counter.', 'sofrah-order-board' ), 'collected' => __( 'Collected. Thank you.', 'sofrah-order-board' ), 'not_collected' => __( 'This order was not collected.', 'sofrah-order-board' ), /* translators: %s: reason */ 'rejected' => sprintf( __( 'The restaurant could not accept your order. Reason: %s. Nothing is due.', 'sofrah-order-board' ), $reason ), 'cancelled_diner' => __( 'You cancelled this order. Nothing is due.', 'sofrah-order-board' ), /* translators: %s: reason */ 'cancelled_restaurant' => sprintf( __( 'The restaurant cancelled your order. Reason: %s. Nothing is due.', 'sofrah-order-board' ), $reason ), ); return array( 'status' => $status, 'label' => sofrah_board_status_label( $status ), 'explain' => $explain[ $status ] ?? '', 'open' => in_array( $status, SOFRAH_BOARD_OPEN, true ), 'can_cancel' => 'awaiting' === $status, 'updated' => wp_date( get_option( 'time_format' ) ), ); } add_action( 'template_redirect', function () { $page = (int) get_option( 'sofrah_board_status_page' ); if ( $page && is_page( $page ) ) { if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( 'DONOTCACHEPAGE', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- the standard signal to caching plugins. } nocache_headers(); header( 'Referrer-Policy: same-origin' ); // The address holds the order key: never pass it to another site. } } ); add_shortcode( 'sofrah_order_status', function () { $order = sofrah_board_order_for_key( absint( wp_unslash( $_GET['order'] ?? 0 ) ), sanitize_text_field( wp_unslash( $_GET['key'] ?? '' ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- the order key is the credential. if ( ! $order ) { return '
' . esc_html__( 'Open this page from the link in your order email.', 'sofrah-order-board' ) . '
'; } $s = sofrah_board_public_status( $order ); wp_enqueue_style( 'sob-status', SOFRAH_BOARD_URL . 'assets/status.css', array(), SOFRAH_BOARD_VERSION ); wp_enqueue_script( 'sob-status', SOFRAH_BOARD_URL . 'assets/status.js', array(), SOFRAH_BOARD_VERSION, true ); wp_localize_script( 'sob-status', 'sofrahStatus', array( 'url' => esc_url_raw( rest_url( 'sofrah-order-board/v1/status' ) ), 'order' => $order->get_id(), 'key' => $order->get_order_key(), 'confirm' => __( 'Cancel this order?', 'sofrah-order-board' ), 'failed' => __( 'Could not reach the restaurant\'s site. Retrying.', 'sofrah-order-board' ), ) ); ob_start(); ?>get_order_number() ) ); ?>
get_formatted_order_total() ); ?>
>