I have a custom field on a WooCommerce product, and I am entering the ID of another product into it. When saving that product, I am adding a meta field to the product that was inputted, creating a “link” between them. I have this working fine, but the issue is that it adds it even it is already there.
function part_fits($post_id){
global $post;
global $product;
$current_diagram_id = get_the_ID();
if( have_rows('product_association') ):
while( have_rows('product_association') ): the_row();
$single_part_id = get_sub_field('part');
add_post_meta($single_part_id, 'part_fits', $current_diagram_id);
endwhile;
endif;
}
Is there a way I can check if that exact key and value already exists and only add it if it does not?