@felipemonteiro44 $form_data will return array of product data that needs to be saved. Now, in the case of variable products, you need to fetch variations from this array, just like $form_data[‘qtd_atacado’]
Now, you need to run the variations in a foreach loop and then fetch variation_id from this. After that update the meta accordingly.
I tried this other way, but I have not had results yet:
function save_qtd_atacado($variation_id, $i){
global $post;
if( $post->post_type == ‘product’ )
$product = wc_get_product( $post->ID );
$available_variations = $product->get_available_variations();
foreach ( $available_variations as $variation_values ) {
$variation_id = $variation_values[‘variation_id’]; // variation id
}
update_post_meta($variation_id, ‘qtd_atacado’, $_POST[‘qtd_atacado’][$i]);
}
add_action(‘woocommerce_save_product_variation’, ‘save_qtd_atacado’, 10, 2);
@felipemonteiro44, the method you were using previously was right, i.e. it is for WCMp. The method you have posted in last thread, that is for WooCommerce.
The $form_data you have used in save_qtd_atacado($product_id, $form_data), which you have created earlier, now fetch the variations like $form_data[‘variations’].
Now, you need to run the variations in a foreach loop and then fetch variation_id from this. After that update the meta accordingly.