get(ExtendSchema::class); self::extend_store(); } /** * Register endpoint data */ public static function extend_store() { if (is_callable([self::$extend, 'register_endpoint_data'])) { self::$extend->register_endpoint_data( array( 'endpoint' => CheckoutSchema::IDENTIFIER, 'namespace' => self::IDENTIFIER, 'schema_callback' => array(self::class, 'extend_checkout_schema'), 'schema_type' => ARRAY_A, ) ); } } /** * Extend checkout schema with custom fields */ public static function extend_checkout_schema() { $schema = array(); $block_manager = CFEP_Block_Field_Manager::instance(); $custom_fields = $block_manager->get_all_fields(null, true); foreach ($custom_fields as $field) { // Skip default WooCommerce fields if ((int) $field['is_default'] === 1) { continue; } $schema[$field['field_key']] = array( 'description' => $field['label'], 'type' => array('string', 'null'), 'context' => array('view', 'edit'), 'readonly' => false, 'arg_options' => array( 'validate_callback' => function($value) { return true; }, ), ); } return $schema; } }