I am able to successfully pull and update post meta as expected using the following.
function update_post_type_post_prodd( $post_id ) {
$personalization = get_post_meta( $post_id, '_qty_discount_code', true );
if ($personalization === 'R'){
$gfdata ='a:28:{s:2:"id";}';
$emptyRemoved = unserialize($gfdata);
update_post_meta( $post_id,'_gravity_form_data', $emptyRemoved );
}
}
add_action( 'save_post_product', 'update_post_type_post_prodd' );
Pull meta field _qty_discount_code
and if it contains the value R
update the meta field _gravity_form_data with $gfdata on post save.
However, when attempting to pull a product attribute taxonomy pa_personalization I get crickets.
I have tried multiple methods to no avail. Does this looks correct?
function update_post_type_post_prodd( $post_id ) {
//$personalization = get_post_meta( $post_id, 'pa_personalization', true );
$taxonomy = 'pa_personalization';
$meta = get_post_meta($post_id, 'attribute_'.$taxonomy, true);
$term = get_term_by('slug', $meta, $taxonomy);
$personalization = $term->name;
if ($personalization === 'yes'){
$emptyRemoved = unserialize($gfdata);
update_post_meta( $post_id,'_gravity_form_data', $emptyRemoved );
}
}
//execute the function whenever post type is being updated
add_action( 'save_post_product', 'update_post_type_post_prodd' );