title: How to update product meta when the woocommerce order status changes
body: <p>Please help me with the code, I need the product to be updated when the order goes to the status completed... Here is my outline of the code, I have been suffering with it for 5 days...</p>
  <pre><code>//Update product meta when the woocommerce order status changes
  add_action( 'woocommerce_payment_complete', 'update_product_meta', 20, 2 );
  add_action( 'woocommerce_order_status_completed', 'update_product_meta', 20, 2 );
  add_action( 'woocommerce_order_status_processing', 'update_product_meta', 20, 2 );
  
   function update_product_meta ($product, $order) {
  
  
   // get product
   $order = get_product( array(
      'post_type'        =&gt; 'product', // or ['product','product_variation'],
      'post_status'      =&gt; 'publish',
      'fields'           =&gt; 'ids',
      'meta_query'       =&gt; array( array(
          'key'     =&gt; '_sync_updated',
          'compare' =&gt; 'NOT EXISTS',
      ) )
  ) );
  
  
      // Get the WC_Product object
      $product = wc_get_product($product_id);
  
      // Mark product as updated
      $product-&gt;update_meta_data( '_sync_updated', true );
  
      $product-&gt;save();
  }
  </code></pre>