verifier = $verifier; } /** * Hooks. */ public function register() { add_action( 'add_meta_boxes', array( $this, 'meta_box' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); add_action( 'wp_ajax_afrihex_recheck', array( $this, 'ajax_recheck' ) ); // Orders list column: legacy posts screen and HPOS screen. add_filter( 'manage_edit-shop_order_columns', array( $this, 'column' ), 20 ); add_action( 'manage_shop_order_posts_custom_column', array( $this, 'column_value_legacy' ), 10, 2 ); add_filter( 'manage_woocommerce_page_wc-orders_columns', array( $this, 'column' ), 20 ); add_action( 'manage_woocommerce_page_wc-orders_custom_column', array( $this, 'column_value' ), 10, 2 ); } /** * The order edit screen ID for the active storage. * * @return string */ private static function screen() { if ( class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() ) { return wc_get_page_screen_id( 'shop-order' ); } return 'shop_order'; } /** * Adds the box beside the order. */ public function meta_box() { add_meta_box( 'afrihex-location', __( 'Delivery location (AfriHex)', 'afrihex-address-for-woocommerce' ), array( $this, 'render_box' ), self::screen(), 'side', 'high' ); } /** * Script for the re-check button and the settings page. */ public function enqueue() { $screen = get_current_screen(); $ours = $screen && ( self::screen() === $screen->id || 'woocommerce_page_' . AfriHex_Settings::PAGE === $screen->id ); if ( ! $ours ) { return; } wp_enqueue_script( 'afrihex-address-admin', AFRIHEX_ADDRESS_URL . 'assets/js/admin.js', array(), AFRIHEX_ADDRESS_VERSION, true ); wp_localize_script( 'afrihex-address-admin', 'afrihexAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'i18n' => array( 'checking' => __( 'Checking…', 'afrihex-address-for-woocommerce' ), 'failed' => __( 'Request failed.', 'afrihex-address-for-woocommerce' ), ), ) ); } /** * Renders the box. * * @param WP_Post|WC_Order $post_or_order Post (legacy) or order (HPOS). */ public function render_box( $post_or_order ) { $order = $post_or_order instanceof WC_Order ? $post_or_order : wc_get_order( $post_or_order->ID ); if ( ! $order ) { return; } $rec = AfriHex_Order_Display::record( $order ); if ( ! $rec ) { echo '
' . esc_html__( 'No delivery location was recorded for this order.', 'afrihex-address-for-woocommerce' ) . '
'; $this->recheck_form( $order, null ); return; } $badge = self::badge( $rec ); echo '' . esc_html( $badge[0] ) . '
'; echo '| ' . esc_html( $r[0] ) . ' | ' . esc_html( $r[1] ) . ' |
|---|
' . esc_html__( 'Open in Google Maps', 'afrihex-address-for-woocommerce' ) . '
'; } if ( ! empty( $rec['issues'] ) ) { echo '' . esc_html( sprintf( __( 'Last error: %s', 'afrihex-address-for-woocommerce' ), $rec['error'] ) ) . '
'; } /* translators: %s: date and time */ echo '' . esc_html( sprintf( __( 'Checked %s', 'afrihex-address-for-woocommerce' ), wc_format_datetime( new WC_DateTime( $rec['checked_at'] ) ) . ' ' . wc_format_datetime( new WC_DateTime( $rec['checked_at'] ), wc_time_format() ) ) ) . '
'; $this->recheck_form( $order, $rec ); } /** * The re-check controls. Not a