I added custom fields to WooCommerce category edit form using add_action('product_cat_edit_form_fields')
and on update action add_action('edited_product_cat')
The fields display correctly.
On update action, the JSON request data shows correctly in the browser's console but not being saved to the database table _options
as set to do and appears that the array key is just not existing in the php $_POST array, as if page edit-tags.php
is not being loaded.
NOTE The process works fine when taxonomy is category
the code on update run time
global $pagenow;
if( 'edit-tags.php' === $pagenow || 'admin-ajax.php' === $pagenow ) {
add_action('edited_product_cat', function($term_id) {
if( array_key_exists('cmse_options',$_POST) ) {
$field_key = $_POST['cmse_options'];
$keys = array_keys($field_key);
foreach($keys as $field_name) {
if( isset($field_key[$field_name]) )
$keys[$field_name] = $field_key[$field_name];
}
// serialize update options
update_option('woo_cat_config_'.$term_id, $keys);
}
});
}
wp_ajax
and the process via edit-tags.php runs. There just is no$_POST
values being passed to the database.