I am using a plugin where I can import products into WooCommerce. The SKU field is not filled in during this process. I cannot find a way to programmatically set the SKU after an item is imported. I have tried many things, and I was sure the code below would work. I could use some help if anyone has an idea of where I am going wrong.
add_action('updated_post_meta', 'my_updated_post_meta', 10, 4);
add_action('added_post_meta', 'my_updated_post_meta', 10, 4);
function my_updated_post_meta($meta_id, $post_id, $meta_key, $meta_value) {
if ($meta_key == '_mySku') {
if (get_post_type($post_id) == 'product') {
update_post_meta($post_id,'_sku',$meta_value);
}
}
}