' . esc_html__('CrocoAI Data Bridge requires WooCommerce.', 'crocoai-data-bridge') . '

'; }); return; } Database::maybeUpgrade(); $bridge = new BridgeService(); $publication = new PublicationService($bridge, new AttributeLookupRebuilder()); (new Scheduler($publication))->register(); (new RestController($bridge, $publication))->register(); (new AdminPage())->register(); // WCML 5.5.7 translates attribute options for the WooCommerce lookup // table by calling set_options() on every value returned by this // filter. During a structural change, WooCommerce can expose a null // placeholder for an attribute that is not present on the duplicate // yet. Remove invalid values before WCML's priority-10 filter runs; // the duplicate receives the complete attribute set later in the same // Croco publication. add_filter( 'woocommerce_product_get_attributes', [self::class, 'validProductAttributes'], 9 ); add_filter( 'wpml_duplicate_custom_fields_exceptions', [WpmlAdapter::class, 'duplicateCustomFieldExceptions'] ); add_filter('woocommerce_attribute_label', static function ($label, $name, $product) { if (!$product instanceof \WC_Product) { return $label; } $labels = (array) LegacyKeys::productMeta($product, 'attribute_labels'); $key = \CrocoAI\DataBridge\Domain\AttributeIdentity::fromProductAttribute((string) $name); return isset($labels[$key]) && $labels[$key] !== '' ? (string) $labels[$key] : $label; }, 20, 3); add_filter('woocommerce_display_product_attributes', static function (array $attributes, \WC_Product $product): array { foreach ((array) LegacyKeys::productMeta($product, 'attribute_labels') as $key => $label) { $row = 'attribute_pa_' . $key; if (isset($attributes[$row]) && $label !== '') { $attributes[$row]['label'] = (string) $label; } } return $attributes; }, 20, 2); do_action('crocoai_dbridge_loaded', $this); } /** * Keep WooCommerce's product-attribute filter contract valid for WCML. * * @param mixed $attributes * @return mixed */ public static function validProductAttributes($attributes) { if (!is_array($attributes)) { return $attributes; } foreach ($attributes as $key => $attribute) { if (!$attribute instanceof \WC_Product_Attribute) { unset($attributes[$key]); } } return $attributes; } }