Almost there!
This is what I have done.
1. I have a package that only allows access for “subscriber” role (package id of 123).
2. If no user is logged in then download button is set to “Register to Unlock” as the “Login Required Message” (under Settings->General) is set to:
<a href="https://mysite.com/wp-login.php?action=register">Register to Unlock"</a>
3. Once registered, the user is assigned the “customer role” by default.
4. Since the user role is not “subscriber” the download button now shows “Generate Key” as the “Permission Denied Message for Packages” (under Settings->General) is set to:
<a href="https://mysite.com/?add_to_cart=123">Generate Key</a>
5. The cart is shown with the added package and the user can then complete the order ($0 cost)
6. The license key is generated and the user role “subscriber” is added to the user.
7. Thus the download button from now on allows direct download to the package.
Works well….
The only drawback is that if I am to create a second package for download with the need for a different license key, then the user is already assigned the “subscriber” role so the download button will bypass the purchase order process. I will have to create a custom role for each package.
Hope this is useful for someone.