I wouldn't recommend doing it with custom code, even though it is possible.
Let me say that in a matter of days I am releasing a free plugin that will allow you to use a proper sales page to sell your course, and when someone is enrolled, they will see the normal course index page.
Initially, it will work with Elementor, so you can show any elementor page. Ultimately I think this is a better solution to the problem because it's just dumb to reveal your exact course syllabus. (my opinion there)
That being said, if you use Beaver Builder you can install LifterLMS Labs and it will allow you full layout control. Both are free.