scorer = $scorer;
add_filter( 'manage_product_posts_columns', array( $this, 'add_column' ) );
add_action( 'manage_product_posts_custom_column', array( $this, 'render_column' ), 10, 2 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
}
/**
* Insert the score column just after the product name.
*
* @param array $columns Existing columns.
* @return array
*/
public function add_column( $columns ) {
if ( ! is_array( $columns ) ) {
return $columns;
}
$new = array();
foreach ( $columns as $key => $label ) {
$new[ $key ] = $label;
if ( 'name' === $key ) {
$new[ self::COLUMN_KEY ] = __( 'Agent score', 'agentictrack-agent-readiness-for-woocommerce' );
}
}
// Fallback: if there was no 'name' column, append it.
if ( ! isset( $new[ self::COLUMN_KEY ] ) ) {
$new[ self::COLUMN_KEY ] = __( 'Agent score', 'agentictrack-agent-readiness-for-woocommerce' );
}
return $new;
}
/**
* Render the score pill for a product row.
*
* @param string $column Column key.
* @param int $post_id Product post ID.
* @return void
*/
public function render_column( $column, $post_id ) {
if ( self::COLUMN_KEY !== $column ) {
return;
}
$product = wc_get_product( $post_id );
if ( ! $product instanceof WC_Product ) {
echo '—';
return;
}
$scored = $this->scorer->score_product( $product );
$score = (int) $scored['score'];
$grade = ARWC_Scorer::grade( $score );
$issues = ( isset( $scored['issues'] ) && is_array( $scored['issues'] ) ) ? count( $scored['issues'] ) : 0;
$fix_url = add_query_arg(
array(
'page' => ARWC_Admin::FIX_PAGE_SLUG,
'arwc_focus' => (int) $post_id,
),
admin_url( 'admin.php' )
);
$title = ( $issues > 0 )
? sprintf(
/* translators: %d: number of issues. */
_n( '%d issue — open in AgenticTrack', '%d issues — open in AgenticTrack', $issues, 'agentictrack-agent-readiness-for-woocommerce' ),
$issues
)
: __( 'Agent-ready — open in AgenticTrack', 'agentictrack-agent-readiness-for-woocommerce' );
printf(
'%4$d',
esc_attr( $grade ),
esc_url( $fix_url ),
esc_attr( $title ),
(int) $score
);
}
/**
* Load the small self-contained pill styles on the Products list screen.
*
* @param string $hook_suffix Current admin page hook.
* @return void
*/
public function enqueue_assets( $hook_suffix ) {
if ( 'edit.php' !== $hook_suffix ) {
return;
}
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( ! $screen || 'product' !== $screen->post_type ) {
return;
}
wp_enqueue_style(
'arwc-metabox',
ARWC_PLUGIN_URL . 'admin/css/metabox.css',
array(),
ARWC_VERSION
);
}
}