core = $core; // Orders list — HPOS, then legacy add_filter( 'manage_woocommerce_page_wc-orders_columns', [ $this, 'add_column' ] ); add_action( 'manage_woocommerce_page_wc-orders_custom_column', [ $this, 'render_column' ], 10, 2 ); add_filter( 'manage_edit-shop_order_columns', [ $this, 'add_column' ] ); add_action( 'manage_shop_order_posts_custom_column', [ $this, 'render_column' ], 10, 2 ); // Order screen box add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ], 30 ); } // ─── Column ─────────────────────────────────────────────────────────────── public function add_column( $columns ) { if ( ! $this->core->modules_supporting( 'orders_column' ) ) return $columns; // Right after the order number $out = []; foreach ( (array) $columns as $key => $label ) { $out[ $key ] = $label; if ( $key === 'order_number' ) $out[ self::COLUMN ] = 'Patchwork'; } if ( ! isset( $out[ self::COLUMN ] ) ) $out[ self::COLUMN ] = 'Patchwork'; return $out; } /** * @param string $column * @param \WC_Order|int $order Order (HPOS) or post ID (legacy). */ public function render_column( $column, $order ): void { if ( $column !== self::COLUMN ) return; $order = $order instanceof \WC_Order ? $order : wc_get_order( $order ); if ( ! $order ) return; foreach ( $this->core->modules_supporting( 'orders_column' ) as $module ) { foreach ( $module->order_badges( $order ) as $badge ) { echo self::badge( $badge ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in badge() } } } /** * Badge HTML. Modules can also use this in their own UI. */ public static function badge( array $badge ): string { $tone = in_array( $badge['tone'] ?? '', [ 'info', 'success', 'warning', 'danger', 'neutral' ], true ) ? $badge['tone'] : 'neutral'; $label = esc_html( $badge['label'] ?? '' ); $title = esc_attr( $badge['title'] ?? '' ); return ! empty( $badge['url'] ) ? sprintf( '%s', esc_url( $badge['url'] ), $tone, $title, $label ) : sprintf( '%s', $tone, $title, $label ); } // ─── Order box ──────────────────────────────────────────────────────────── public function add_meta_box(): void { if ( ! $this->core->modules_supporting( 'order_panel' ) || ! function_exists( 'wc_get_page_screen_id' ) ) return; add_meta_box( 'patchwork-order', 'Patchwork', [ $this, 'render_meta_box' ], wc_get_page_screen_id( 'shop-order' ), 'side', 'default' ); } /** * @param \WP_Post|\WC_Order $post_or_order */ public function render_meta_box( $post_or_order ): void { $order = $post_or_order instanceof \WC_Order ? $post_or_order : wc_get_order( $post_or_order->ID ); if ( ! $order ) return; $sections = 0; foreach ( $this->core->modules_supporting( 'order_panel' ) as $module ) { $html = $module->order_panel( $order ); if ( $html === '' ) continue; $sections++; echo '
' . esc_html__( 'Nothing to show for this order yet.', 'patchwork-order-split' ) . '
'; } } }