Hi –
I have realised that the code box is an existing one (not a Snippets one) and one that does work on another website
The code that I have used to try to add a new Snippets Custom Code Box doesn’t create a new Custom Code box to display…
Please can you advise the code that would work? It is to add schema for Woocommerce Categories
Custom Code Box for WooCommerce Categories – Many Thanks
// Add custom field to WooCommerce category edit screen
add_action('product_cat_add_form_fields', 'add_custom_schema_field');
add_action('product_cat_edit_form_fields', 'edit_custom_schema_field');
// Display custom field on create screen
function add_custom_schema_field() {
?>
Custom Schema Code
Enter custom schema or code for this category.
<?php
}
// Display custom field on edit screen
function edit_custom_schema_field($term) {
$value = get_term_meta($term->term_id, 'custom_schema_code', true);
?>
Custom Schema Code <?php echo esc_textarea($value); ?>
Enter custom schema or code for this category.
<?php
}
// Save the custom field
add_action('created_product_cat', 'save_custom_schema_field');
add_action('edited_product_cat', 'save_custom_schema_field');
function save_custom_schema_field($term_id) {
if (isset($_POST['custom_schema_code'])) {
update_term_meta($term_id, 'custom_schema_code', sanitize_textarea_field($_POST['custom_schema_code']));
}
}
-
This reply was modified 3 months, 1 week ago by
Gemini23.