title: Custom code is not working after updating the woocommerce 5.5 to 6
body: <p>I created the custom code for punching the stock value (only for variable &amp; simple product).This custom code will work/punch when the new product added in woocommerce via admin dashboard .For this i am using the the action hook called -</p>
  <blockquote>
  <p>added_post_meta</p>
  </blockquote>
  <p>My custom code for reading the stock value is</p>
  <pre><code>function wc_set_product_stock_callback_post_meta_new($meta_id, $post_id, $meta_key, $meta_value )
  {
      global $wpdb;
      global $current_user;
      global $post;   
  
      if(get_post_type( $post_id ) == 'product' &amp;&amp; get_post_status( $post_id ) == 'publish')
          {
              $product_id = $post_id;
              $tablename = $wpdb-&gt;prefix.'woocommerce_stock_master';
              if(!$product_id)
              {
                  return;
              }  
  
              wp_get_current_user();
              $user_id = $current_user-&gt;ID;
  
              // get an instance of the WC_Product Object
              $product    = wc_get_product( $product_id );
  
              $current_product_id = $product-&gt;get_id(); 
              $stock_qty  = $product-&gt;get_stock_quantity();
              $stock_notes = 'New Stock';
              $producut_in_master = check_stock_in_master($current_product_id);
              $is_stock = get_post_meta( $current_product_id , '_stock',true);
              $product_type = $product-&gt;get_type();
              $manage_stock = get_post_meta( $current_product_id , '_manage_stock',true);
             
             if ($product-&gt;is_type( 'variable' )){
                   //$product_id = $product-&gt;get_id(); 
                   $manage_stock_var = get_post_meta( $current_product_id , '_manage_stock',true);
  
                   if($manage_stock_var == 'yes')
                   {
                      $current_stk = $stock_qty;         
                      if(empty($current_stk))//Stock Value Check - Product Added But with No/Empty Stock Value
                      {
                          $stock_notes = 'New Stock with 0 Qty';
                      }      
                      $wpdb-&gt;insert( $tablename, array( 'post_ID' =&gt;  $current_product_id, 'user_ID' =&gt; $user_id, 'stock_quantity'=&gt;  $current_stk ,'notes'=&gt; $stock_notes,'product_type' =&gt;$product_type ) );
                   }
                  $variations = $product-&gt;get_children(); // get variations
                  foreach ($variations as $variations_value) {
                      $single_variation = new WC_Product_Variation($variations_value);
                      $single_variation_stock = $single_variation-&gt;get_stock_quantity();
                      $variation_producut_in_master = check_stock_in_master($variations_value);
                      $manage_stock_variation = get_post_meta( $variations_value , '_manage_stock',true);
                      if($variation_producut_in_master &lt;= 0 &amp;&amp; $manage_stock_variation == 'yes')
                      {
                          $variation_current_stk = $single_variation_stock;
                          if(empty($variation_current_stk))//Stock Value Check - Variation Product Added But with No/Empty Stock Value
                          {
                          $stock_notes = 'New variation Stock with 0 Qty';
                          } 
                          $wpdb-&gt;insert( $tablename, array( 'post_ID' =&gt; $variations_value, 'user_ID' =&gt; $user_id, 'stock_quantity'=&gt;  $variation_current_stk ,'notes'=&gt; $stock_notes,'product_type' =&gt;$product_type,'variation_of' =&gt; $current_product_id) );
                      }
                  }
             }
             if ($product-&gt;is_type( 'simple' )){
                  if($producut_in_master &lt;= 0 &amp;&amp; $manage_stock == 'yes')
                  {
                      if($is_stock !='')
                      {
                          $simple_current_stk = $stock_qty;
                          if($simple_current_stk == 0)//Stock Value Check - Product Added But with No/Empty Stock Value
                          {
                              $stock_notes = 'New Stock with 0 Qty';
                          }   
                          $wpdb-&gt;insert( $tablename, array( 'post_ID' =&gt;  $current_product_id, 'user_ID' =&gt; $user_id, 'stock_quantity'=&gt;  $simple_current_stk ,'notes'=&gt; $stock_notes,'product_type' =&gt;$product_type) );
                      }    
                  }
              }
          }else{
              return;
          }
          error_log('Quantity is '.$stock_qty . &quot;--&quot;.$producut_in_master );   
    
         
  }
  </code></pre>
  <p>And calling the call back function like this -</p>
  <blockquote>
  <p>add_action( 'added_post_meta','wc_set_product_stock_callback_post_meta_new',10,4);</p>
  </blockquote>
  <p><strong>Custom table SQL</strong></p>
  <pre><code>CREATE TABLE `wp_custom_woocommerce_stock_master` (
    `id` int(11) NOT NULL,
    `post_id` bigint(20) NOT NULL,
    `user_id` bigint(20) NOT NULL,
    `stock_quantity` int(11) DEFAULT NULL,
    `adjust_stock` int(11) NOT NULL,
    `notes` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `product_type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `variation_of` bigint(20) DEFAULT NULL,
    `date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
    `last_update` timestamp NOT NULL DEFAULT current_timestamp()
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  </code></pre>
  <p><strong>Custom function code</strong></p>
  <pre><code>function check_stock_in_master($post_ID)
  {
  /* This function will read the value from wp_woocommerce_stock_master according to post ID 
      And reurn an $rowcount
   */
      global $post;
      global $wpdb;
      $current_post = $post_ID;
      $results = $wpdb-&gt;get_results( &quot;SELECT * FROM wp_woocommerce_stock_master WHERE post_id =  $current_post&quot;);
      $rowcount = $wpdb-&gt;num_rows;
      return $rowcount;
  }
  </code></pre>
  <p>My this implementation was working fine with WP-5.8.2 &amp; WC 5.5.2. But after updating the wooCommerce 6 same code for variable product is not working. After debugging the code i found that, in woocommerce 6  the following if block is not working as expected.</p>
  <blockquote>
  <p>if(get_post_type( $post_id ) == 'product' &amp;&amp; get_post_status( $post_id ) == 'publish')</p>
  </blockquote>
  <p>Is there any difference in internal working of WC5.5 &amp; WC6.0. OR i was using the wrong hook for punching/reading the stock values.Or is there any other way for reading the value of stock when the new product added.</p>
  <p><strong>UPDATE on 13-01-22</strong></p>
  <p>I tried the action hook <em>woocommerce_update_product</em> suggested in <a href="https://www.mootpoint.org/blog/woocommerce-hook-product-updated-added/" rel="nofollow noreferrer">https://www.mootpoint.org/blog/woocommerce-hook-product-updated-added/</a></p>
  <p>After replacing the hook, code is working but it seems this hook  woocommerce_update_product runs twice.Due to this i am getting two row for each new product inserted. Why it is running twice.</p>
  <p>Any one please advice on this.</p>