Title: Save metada product variable
Last modified: October 22, 2018

---

# Save metada product variable

 *  Resolved [felipemonteiro44](https://wordpress.org/support/users/felipemonteiro44/)
 * (@felipemonteiro44)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/save-metada-product-variable/)
 * I have the following code to save the data from my custom field of the add-product
   page. With simple products it works very well. More when it is a variable product
   I need to add a different value to the target for each variation. How do I do
   that?
 * function save_qtd_atacado($product_id, $form_data){
    update_post_meta($product_id,‘
   qtd_atacado’, $form_data[‘qtd_atacado’]); } add_action(‘after_wcmp_fpm_meta_save’,‘
   save_qtd_atacado’, 10, 2);

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [DualCube](https://wordpress.org/support/users/dualcube/)
 * (@dualcube)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/save-metada-product-variable/#post-10806873)
 * [@felipemonteiro44](https://wordpress.org/support/users/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.
 *  Thread Starter [felipemonteiro44](https://wordpress.org/support/users/felipemonteiro44/)
 * (@felipemonteiro44)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/save-metada-product-variable/#post-10816512)
 * 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);
 *  [DualCube](https://wordpress.org/support/users/dualcube/)
 * (@dualcube)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/save-metada-product-variable/#post-10818345)
 * [@felipemonteiro44](https://wordpress.org/support/users/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.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Save metada product variable’ is closed to new replies.

 * ![](https://ps.w.org/dc-woocommerce-multi-vendor/assets/icon-256x256.gif?rev=
   3314608)
 * [MultiVendorX - WooCommerce Multivendor Marketplace AI Powered Solutions](https://wordpress.org/plugins/dc-woocommerce-multi-vendor/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/dc-woocommerce-multi-vendor/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor/)
 * [Active Topics](https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [DualCube](https://wordpress.org/support/users/dualcube/)
 * Last activity: [7 years, 6 months ago](https://wordpress.org/support/topic/save-metada-product-variable/#post-10818345)
 * Status: resolved