get_id() ); } /** * {@inheritDoc} */ public function run( WC_Product $product ) { $result = $this->result(); $attribute_count = $this->count_visible_attributes( $product ); $has_weight = '' !== trim( (string) $product->get_weight() ); $has_dimensions = $this->has_dimensions( $product ); // Sub-scores: attributes are the bulk (0.6), physical props split the rest. $attr_score = min( 1.0, $attribute_count / 3 ); // 3+ attributes = full marks. $score = ( $attr_score * 0.6 ) + ( $has_weight ? 0.2 : 0.0 ) + ( $has_dimensions ? 0.2 : 0.0 ); $result->set_score( $score ); if ( 0 === $attribute_count ) { $result->add_issue( 'no_attributes', __( 'No product attributes set — add material, size, color, brand, etc.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_CRITICAL ); } elseif ( $attribute_count < 3 ) { $result->add_issue( 'few_attributes', sprintf( /* translators: %d: number of attributes currently set. */ __( 'Only %d attribute(s) set — agents compare better with 3 or more structured attributes.', 'agentictrack-agent-readiness-for-woocommerce' ), (int) $attribute_count ), ARWC_Check_Result::SEVERITY_WARNING ); } // Physical dimensions are only relevant for shippable goods. if ( $product->needs_shipping() ) { if ( ! $has_weight ) { $result->add_issue( 'missing_weight', __( 'No weight set — useful for shipping estimates and physical comparisons.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_INFO ); } if ( ! $has_dimensions ) { $result->add_issue( 'missing_dimensions', __( 'No dimensions set (length, width, height).', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_INFO ); } } return $result; } /** * Count attributes that carry actual values. * * Works for both taxonomy-based and custom product attributes. * * @param WC_Product $product Product. * @return int */ protected function count_visible_attributes( WC_Product $product ) { $attributes = $product->get_attributes(); if ( empty( $attributes ) ) { return 0; } $count = 0; foreach ( $attributes as $attribute ) { if ( ! $attribute instanceof WC_Product_Attribute ) { continue; } $options = $attribute->get_options(); if ( ! empty( $options ) ) { $count++; } } return $count; } /** * Whether all three dimensions are present. * * @param WC_Product $product Product. * @return bool */ protected function has_dimensions( WC_Product $product ) { return '' !== trim( (string) $product->get_length() ) && '' !== trim( (string) $product->get_width() ) && '' !== trim( (string) $product->get_height() ); } }