get_id() ); } /** * {@inheritDoc} */ public function run( WC_Product $product ) { $result = $this->result(); $has_sku = '' !== trim( (string) $product->get_sku() ); $has_gtin = $this->has_gtin( $product ); // GTIN is weighted more heavily than SKU for agent matching. $score = 0.0; if ( $has_gtin ) { $score += 0.6; } if ( $has_sku ) { $score += 0.4; } $result->set_score( $score ); if ( ! $has_gtin ) { $result->add_issue( 'missing_gtin', __( 'No GTIN/UPC/EAN set — agents cannot match this product to a global catalog entry.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_CRITICAL ); } if ( ! $has_sku ) { $result->add_issue( 'missing_sku', __( 'No SKU set — add a unique stock-keeping identifier.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_WARNING ); } return $result; } /** * Determine whether the product has any usable GTIN value. * * Prefers the native WooCommerce global unique ID (WC 9.2+) and falls back * to common third-party meta keys. * * @param WC_Product $product Product. * @return bool */ protected function has_gtin( WC_Product $product ) { if ( is_callable( array( $product, 'get_global_unique_id' ) ) ) { $native = trim( (string) $product->get_global_unique_id() ); if ( '' !== $native ) { return true; } } foreach ( $this->legacy_gtin_meta_keys as $key ) { $value = $product->get_meta( $key, true ); if ( is_string( $value ) && '' !== trim( $value ) ) { return true; } } return false; } }