Created
April 21, 2022 03:52
-
-
Save GauravKhupse/ed6a5c2ec0f3da61a3041fe57fc39a11 to your computer and use it in GitHub Desktop.
Add Extra ID field for product schema.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'after_setup_theme', 'add_my_custom_meta_field' ); | |
function add_my_custom_meta_field() { | |
add_filter( 'wp_schema_pro_schema_meta_fields', 'my_extra_schema_field' ); | |
add_filter( 'wp_schema_pro_schema_product', 'my_extra_schema_field_mapping', 10, 3 ); | |
} | |
/** | |
* Add fields for mapping. | |
* | |
* @param array $fields Mapping fields array. | |
* @return array | |
*/ | |
function my_extra_schema_field( $fields ) { | |
$fields['bsf-aiosrs-product']['subkeys']['id'] = array( // `bsf-aiosrs-book` used for Book, `bsf-aiosrs-event` will for Event like that. | |
'label' => esc_html__( 'ID', 'aiosrs-pro' ), // Label to display in Mapping fields | |
'type' => 'text', // text/date/image | |
'default' => 'none', | |
); | |
return $fields; | |
} | |
/** | |
* Mapping extra field for schema markup. | |
* | |
* @param array $schema Schema array. | |
* @param array $data Mapping fields array. | |
* @return array | |
*/ | |
function my_extra_schema_field_mapping( $schema, $data, $post ) { | |
if ( isset( $data['id'] ) && ! empty( $data['id'] ) ) { | |
// For date/text type field | |
$schema['id'] = esc_html( $data['id'] ); | |
// For image type field | |
// $schema['workExample'] = BSF_AIOSRS_Pro_Schema_Template::get_image_schema( $data['work-example'] ); | |
} | |
return $schema; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment