$label ) { $new[ $key ] = $label; if ( 'order_status' === $key ) { $new['codg'] = __( 'OrderProof', 'orderproof' ); } } if ( ! isset( $new['codg'] ) ) { $new['codg'] = __( 'OrderProof', 'orderproof' ); } return $new; } public static function render_column_legacy( $column, $post_id ) { if ( 'codg' === $column ) { self::render_column( $column, wc_get_order( $post_id ) ); } } public static function render_column( $column, $order ) { if ( 'codg' !== $column || ! $order instanceof WC_Order ) { return; } $history = codg_customer_history( codg_order_phone( $order ), $order->get_id() ); printf( '%s ', esc_url( codg_whatsapp_url( $order ) ), esc_html__( 'WhatsApp', 'orderproof' ) ); self::history_badge( $history ); do_action( 'codg_admin_column_after', $order, $history ); } private static function history_badge( $history ) { if ( 0 === $history['total'] ) { echo '' . esc_html__( 'New customer', 'orderproof' ) . ''; return; } printf( '✔ %d   ✖ %d', esc_attr__( 'Previous orders: delivered / refused or cancelled', 'orderproof' ), (int) $history['delivered'], (int) $history['failed'] ); } public static function add_meta_box() { foreach ( array( 'shop_order', 'woocommerce_page_wc-orders' ) as $screen ) { add_meta_box( 'codg-box', __( 'OrderProof', 'orderproof' ), array( __CLASS__, 'render_meta_box' ), $screen, 'side', 'high' ); } } public static function render_meta_box( $post_or_order ) { $order = $post_or_order instanceof WC_Order ? $post_or_order : wc_get_order( $post_or_order->ID ); if ( ! $order ) { return; } $phone = codg_order_phone( $order ); $history = codg_customer_history( $phone, $order->get_id() ); echo '

' . esc_html__( 'Customer history', 'orderproof' ) . '
'; printf( /* translators: 1: total orders 2: delivered 3: refused/cancelled 4: in progress */ esc_html__( '%1$d previous orders: %2$d delivered, %3$d refused/cancelled, %4$d in progress', 'orderproof' ), (int) $history['total'], (int) $history['delivered'], (int) $history['failed'], (int) $history['pending'] ); echo '

'; if ( $order->has_status( 'codg-otp' ) ) { echo '

' . esc_html__( 'Waiting for the WhatsApp code', 'orderproof' ) . '

'; } elseif ( $order->get_meta( '_codg_otp_verified' ) ) { echo '

✔ ' . esc_html__( 'Phone verified on WhatsApp', 'orderproof' ) . '

'; } do_action( 'codg_meta_box_before_buttons', $order, $history ); printf( '

%s

', esc_url( codg_whatsapp_url( $order ) ), esc_html__( 'Confirm on WhatsApp', 'orderproof' ) ); if ( $phone ) { printf( '

%s

', esc_attr( $phone ), esc_html__( 'Call customer', 'orderproof' ) ); } do_action( 'codg_meta_box_after_buttons', $order, $history ); $url = wp_nonce_url( admin_url( 'admin-post.php?action=codg_blacklist&order_id=' . $order->get_id() ), 'codg_blacklist_' . $order->get_id() ); printf( '

%s

', esc_url( $url ), esc_js( __( 'Blacklist this phone, email and IP?', 'orderproof' ) ), esc_html__( 'Blacklist this customer', 'orderproof' ) ); } public static function handle_blacklist() { $order_id = isset( $_GET['order_id'] ) ? absint( $_GET['order_id'] ) : 0; check_admin_referer( 'codg_blacklist_' . $order_id ); if ( ! current_user_can( 'edit_shop_orders' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'orderproof' ) ); } $order = wc_get_order( $order_id ); if ( $order ) { codg_blacklist_order( $order ); } wp_safe_redirect( add_query_arg( 'codg_blacklisted', 1, wp_get_referer() ? wp_get_referer() : admin_url() ) ); exit; } public static function notices() { if ( isset( $_GET['codg_blacklisted'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification echo '

' . esc_html__( 'Customer added to the OrderProof blacklist.', 'orderproof' ) . '

'; } } public static function styles() { $screen = get_current_screen(); if ( ! $screen || ! in_array( $screen->id, array( 'edit-shop_order', 'shop_order', 'woocommerce_page_wc-orders' ), true ) ) { return; } wp_enqueue_style( 'codg-admin', CODG_URL . 'assets/css/admin.css', array(), CODG_VERSION ); } }