get_id() ); } /** * {@inheritDoc} */ public function run( WC_Product $product ) { $result = $this->result(); // Five fields that materially affect Product schema richness/validity. $signals = array( 'image' => $product->get_image_id() > 0, 'price' => $this->has_price( $product ), 'description' => '' !== trim( wp_strip_all_tags( (string) $product->get_description() . ' ' . (string) $product->get_short_description() ) ), 'identifier' => $this->has_identifier( $product ), 'category' => $this->has_category( $product ), ); $present = count( array_filter( $signals ) ); $total = count( $signals ); $result->set_score( $total > 0 ? $present / $total : 0.0 ); if ( ! $signals['image'] ) { $result->add_issue( 'schema_no_image', __( 'No product image — Product schema (and agent listings) need an image.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_WARNING ); } if ( ! $signals['price'] ) { $result->add_issue( 'schema_no_offer', __( 'No price — schema "offers" will be incomplete, so agents may skip the product.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_CRITICAL ); } if ( ! $signals['description'] ) { $result->add_issue( 'schema_no_description', __( 'No description for the schema "description" property.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_WARNING ); } if ( ! $signals['identifier'] ) { $result->add_issue( 'schema_no_identifier', __( 'No SKU/GTIN to populate schema productID/gtin — weakens agent matching.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_WARNING ); } if ( ! $signals['category'] ) { $result->add_issue( 'schema_no_category', __( 'No product category assigned — agents use category for relevance.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_INFO ); } return $result; } /** * Whether the product has a usable price. * * @param WC_Product $product Product. * @return bool */ protected function has_price( WC_Product $product ) { $price = $product->get_price(); return '' !== (string) $price && is_numeric( $price ) && (float) $price > 0; } /** * Whether the product has a SKU or any GTIN. * * @param WC_Product $product Product. * @return bool */ protected function has_identifier( WC_Product $product ) { if ( '' !== trim( (string) $product->get_sku() ) ) { return true; } if ( is_callable( array( $product, 'get_global_unique_id' ) ) ) { return '' !== trim( (string) $product->get_global_unique_id() ); } return false; } /** * Whether the product is assigned to at least one category. * * @param WC_Product $product Product. * @return bool */ protected function has_category( WC_Product $product ) { $ids = $product->get_category_ids(); return ! empty( $ids ); } }