id, array( wc_get_page_screen_id( 'shop-order' ), 'shop_order' ), true ) ) { wp_enqueue_script( 'abs-courier-order-box', plugins_url( 'assets/admin/order-box.js', ABS_COURIER_FILE ), array(), ABS_COURIER_VERSION, true ); } } /** * Registers the box on the order screen. * * @return void */ public static function add() { add_meta_box( 'abs-courier', __( 'ABS Courier', 'abs-courier' ), array( __CLASS__, 'render' ), wc_get_page_screen_id( 'shop-order' ), 'side', 'high' ); } /** * Renders the box. * * @param \WP_Post|\WC_Order $post_or_order Order (HPOS) or post (legacy). * @return void */ public static function render( $post_or_order ) { $order = $post_or_order instanceof \WC_Order ? $post_or_order : wc_get_order( $post_or_order->ID ); if ( ! $order instanceof \WC_Order ) { return; } $state = OrderMeta::state( $order ); $awb = (string) $order->get_meta( OrderMeta::AWB ); $error = (string) $order->get_meta( OrderMeta::ERROR ); if ( OrderMeta::CREATED !== $state ) { // For created shipments the AWB and status lines below say the same thing. echo '
' . wp_kses_post( OrderList::badge( $order ) ) . '
'; } if ( '' !== $awb ) { echo '' . esc_html__( 'AWB:', 'abs-courier' ) . ' ' . esc_html( $awb ) . '
'; } $status = (string) $order->get_meta( OrderMeta::STATUS ); if ( '' !== $status ) { $at = (int) $order->get_meta( OrderMeta::STATUS_AT ); echo '' . esc_html__( 'Status:', 'abs-courier' ) . ' ' . esc_html( \ABSCourier\Shipments\Statuses::label( $status ) ) . '';
if ( $at > 0 ) {
echo '
' . esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $at ) ) . '';
}
echo '
' . esc_html__( 'District:', 'abs-courier' ) . ' ' . esc_html( DistrictDirectory::name( $district ) ); if ( 'yes' === $order->get_meta( OrderMeta::DISTRICT_UNMATCHED ) ) { echo ' (' . esc_html__( 'not matched', 'abs-courier' ) . ')'; } echo '
'; } if ( '' !== $error && OrderMeta::CREATED !== $state ) { echo '' . esc_html( $error ) . '
'; } $id = $order->get_id(); if ( in_array( $state, array( '', OrderMeta::FAILED, OrderMeta::HELD, OrderMeta::CANCELED ), true ) ) { self::district_picker( $order ); self::button( OrderActions::url( OrderActions::SEND, $id ), '' === $state ? __( 'Send to ABS', 'abs-courier' ) : __( 'Send again', 'abs-courier' ), true ); } elseif ( OrderMeta::UNKNOWN === $state ) { self::button( OrderActions::url( OrderActions::SEND, $id ), __( 'Check again', 'abs-courier' ), true ); } elseif ( OrderMeta::CREATED === $state ) { printf( '%2$s', esc_url( PrintView::url( array( $awb ) ) ), esc_html__( 'Print waybill', 'abs-courier' ) ); printf( '%2$s', esc_url( add_query_arg( 'awb', rawurlencode( $awb ), Menu::url( 'shipments' ) ) ), esc_html__( 'Details', 'abs-courier' ) ); self::button( OrderActions::url( OrderActions::REFRESH, $id ), __( 'Refresh status', 'abs-courier' ), false ); self::button( OrderActions::url( OrderActions::CANCEL, $id ), __( 'Cancel shipment', 'abs-courier' ), false, __( 'Cancel this ABS shipment? Only shipments not yet picked up can be cancelled.', 'abs-courier' ) ); } } /** * District selector, with the save button. * * @param \WC_Order $order Order. * @return void */ private static function district_picker( \WC_Order $order ) { try { $districts = DistrictDirectory::all(); } catch ( AbsError $e ) { echo '' . esc_html__( 'The district list could not be loaded from ABS Courier.', 'abs-courier' ) . '
'; return; } $current = (int) $order->get_meta( OrderMeta::DISTRICT_ID ); echo '
';
echo '