I read a article, and knew I can override the woocommerce template. woocommerce account pages can not be inserted any content, once added anything, all those will be brought into order, account detail, download pages, but in dashboard page, I would like to place more information, because my site has other more complex information, for example cred front end submission form etc. so, I copied dashboard.php to mysite-child-theme/woocommerce/myaccount/dashboard.php. I have tried that I can hide something on the dashboard page. but in my case, I want to make the page more flexible, so I think if I can insert a content template on this page if possible? 🙂
Thank you so much!
What you are describing falls outside the expected use of Content Templates which are intended to allow you to customise content without having to edit the PHP templates, rather than embedding them in PHP templates.
A Content Template is stored in wp_posts with a post id (the post_type is view_template).
So in theory, knowing the ID of the template, you could output it in a PHP file by just outputting the content of that post. You will want to make sure the shortcodes are parsed, though, meaning you need to pass it through the_content filter.
I haven't tested it but you could try outputting a Content Template in a PHP template like so:
$template = get_post( $id ); // Edit the ID
echo apply_filters( 'the_content', $template->post_content );
If you encounter problems with what is output I'd say that may be expected, as this is not the intended use of Content Templates.
Hi Nigel,
Thank you so much for you response, I have tried using the code you provided. just replace the $id to $id=5678 right? note, 5678 is toolset content template id. but it seems not working. I found I can add some html into dashboard.php, and appearing fine. but I am just afraid, all these data I embed into dashboard.php that can not be bilingual by WPML. because I found nowhere to translate the string. I also accept adding some html code and content on the file. but no way to translate them. what I should do?
I just tested this locally with a very basic CT that outputs some simple HTML, and then I used the same code as above inserted into the dashboard.php file to output the content of the template in the dashboard, and it worked.
So, in principle you can do it, though I can't be sure of what results to expect if you start to add more complex content to the template.
If you edit dashboard.php and want to add text directly to it, for it to be translatable you must output it using gettext, as described in the "Strings for Translation" section of this page: https://codex.wordpress.org/I18n_for_WordPress_Developers
Hi Nigel, Now it is working fine. I can add some html code and text except Toolset view, but tollset content template working fine! Thank you so much! 🙂