Note:
- This is a developer level document and assumes you have knowledge of WordPress shortcodes
- WooNinja do not offer support for the use or implementation of shortcodes in custom code or themes.
- The WooCommerce Extension for Thinkific utilised Carbon Fields for storage and their methods should be used.
[thinkific_has_purchased_course] Content to show if purchased / currently enrolled / previously enrolled [/thinkific_has_purchased_course]
This shortcode determines if a logged in user has previously purchased the linked WooCommerce product. This shortcode should be used on WooCommerce product pages (Or the WooCommerce Product ID passed in the parameters).
Note, this first searches the WooCommerce Order database and falls back to search on the Thinkific API. It does not determine if the enrolment is active, only that the user has purchased and/or been enrolled on the course at any time in the past.
[thinkific_woocommerce_field field="field_id"]
The plugin enriches any WooCommerce product that is linked to a Thinkific Course or Bundle with meta data (Note: You must enable Sync Data from Thinkific in the given WooCommerce product). This meta data is displayed on the WooCommerce product page.
For example, if you wanted to display the Thinkific Product Name, you would use:
[thinkific_woocommerce_field field="product_name"]
Where “product_name” is the lower case, underscore separated string as given from the WooCommerce Product page e.g. Product Name would become product_name, Course Slug would become course_slug
[thinkific_woocommerce_field field="course_slug"]
The repeater field is the most advance field. In this example, it will echo out a simple list of URLs that would allow a user to directly access a course:
[thinkific_woocommerce_repeater field="course_content" type="_" subfield="take_url"]
If you wanted to render a list of the module names, this short code could be used:
[thinkific_woocommerce_repeater field="course_content" type="_" subfield="content"]
If you wanted to output a list of chapters for a given course, you could create your own shortcode by placing the following code in functions.php
/**
* Renders the Thinkific Chapters as shortcode
*/
add_shortcode( 'thinkific_woocommerce_my_chapters', 'thinkific_woocommerce_my_chapters' );
function thinkific_woocommerce_my_chapters( $atts ) {
$rows = carbon_get_post_meta( get_the_ID(), "course_content" );
$uniqueChapters = [];
$markup = '';
if ( ! empty( $rows ) ) {
foreach ( $rows as $row ) {
if ( isset( $row['chapter'] ) && ! in_array( $row['chapter'], $uniqueChapters ) ) {
$uniqueChapters[] = $row['chapter'];
}
}
}
if ( ! empty( $uniqueChapters ) ) {
$markup .= '<ul>';
foreach ( $uniqueChapters as $chapter ) {
$markup .= '<li>';
$markup .= wpautop( $chapter );
$markup .= '</li>';
}
$markup .= '</ul>';
}
return $markup;
}