I have 3 custom fields (image_url, image_alt, attach_id) which are used to save values from a custom metabox for a specific kind of featured image which overrides the standard featured image and sets it to the source of the image_url custom field.
The image_url image is uploaded to the media library automatically, and it is attached to the post via ajax, and its attach_id is updated with similar instruction to the image_url in the save post hook:

add_action(‘save_post’, ‘cndm_save_properties’, 10, 3);

function cndm_save_properties($post_id, $post, $update) {


update_post_meta($post_id, ‘cndm_image_url’, esc_url($_POST[‘cndm_image_url’]));
update_post_meta($post_id, ‘cndm_attach_id’, $_POST[‘cndm_attach_id’]);
..
$success = set_post_thumbnail( $post_id, $_POST[‘cndm_attach_id’]);
..
}

This works very well for standard blog posts and for pages as well. But for Products, which are a custom post type from Woocommerce in this instance, the update_post_meta fires with proper values in the $_POST arguments, but the custom field which displays in the Product page and has the same key is never saved. There is no error message and i am a little lost as to why this happens.

Any idea why this behaviour is noticed? I was assuming that even a custom post, such as woocommerce products, would allow to save regular custom fields. I do not test the post_type to run the update_post_meta conditionnally because it has to apply to all post types i have so far, and it is working well for the Pages post type too.

Read more here: custom fields used for blog, page and product Post types but values not saved when it is a woocommerce product post type


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: