How to add custom attribute to all outofstock and all instock products automatically?

WooCommerce already saves a custom metadata called _stock_status.
This metadata can have these values:

instock
outofstock
onbackorder

You don’t need to create your own metadata as that would be redundant and more difficult to keep in sync with WooCommerce data.

error code: 523