I have added 2 custom fields in a WooCommerce installation using the instructions on this link. It works to save the values but I'm having some problem changing/updating values.
Here is my code that handles the saving:
// Hook save action to database
add_action('woocommerce_process_product_meta', 'woocommerce_save_fields');
// Save field to database
function woocommerce_save_fields($post_id)
{
$myField = $_POST['field_name'];
if (!empty($myField))
update_post_meta($post_id, 'field_name', esc_attr($myField), esc_attr($myField));
else update_post_meta( $post_id, 'field_name', '' );
}
The if (!empty(...))
saves the field value when first adding it.
The else ...
allows to empty the field and delete it's value.
But I still can't just change the value. And after deleting, I can't save a new value to the fields.
I know my problem is inside this function. But I can't figure it out. Any tips on this?
Thanks