I use WordPress and WooCommerce in my site to sell some rent service.
After user's successful payment, I need to generate access pass code for the user. For pass code generation I use php script, but I don't understand where I should place it. I've tried to place it in /plugins/woocommerce/templates/checkout/thankyou.php file, it works, but when user refresh this page, scripts starts again and user get new pass code - this is not good.
So, first question is: where and how I should start my PHP-code to generate pass code after successful payment?
Second question is: how I should store this pass code in user's personal cabinet? I have idea to store this pass code in order's meta data, but I can't find out how I should set this data and get this data from DB.