LearnDash Certificate Generator
Code that will check if there is a WooCommerce order with the same name, and upon completion of LD course generate a post with custom public Certificate that you can later share on your social media.
by Milos Milosevic · github.com/mmilosevic87/learndash_certificates
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/mmilosevic87/learndash_certificates/archive/refs/heads/main.zipA WordPress plugin that automatically generates a certificate and sends a notification email when a user completes a LearnDash course.
What It Does
When a student completes a LearnDash course, this plugin:
- Verifies the purchase — Checks the user's WooCommerce orders to confirm they purchased the course
- Prevents duplicates — Checks if a certificate already exists for this user + course combination
- Generates a certificate — Creates an
urban_certificatescustom post type with a styled HTML certificate containing the student's name, course name, and completion date - Sends an email — Notifies the student via email that their certificate has been generated
How It Works
The plugin hooks into LearnDash's learndash_course_completed action. When fired:
- Validates the incoming course and user data
- Queries WooCommerce orders to find a matching purchase
- Builds a styled HTML certificate with:
- Student's full name
- Course name
- Completion date (localized to WordPress date format)
- Inserts the certificate as a published
urban_certificatespost - Stores
_certificate_user_idand_certificate_course_idas post meta for deduplication - Sends an HTML notification email to the student
Requirements
- WordPress 5.0+
- LearnDash LMS plugin (active)
- WooCommerce plugin (active) — courses must be sold as WooCommerce products
- A registered custom post type:
urban_certificates
Installation
- Download or clone this repository
- Place the
learndash_certificatesfolder inwp-content/plugins/(or dropld_certificates.phpintowp-content/mu-plugins/for must-use) - Activate the plugin from the WordPress admin
- Ensure the
urban_certificatescustom post type is registered by your theme or another plugin
Configuration
No settings page is needed. The plugin works automatically via the learndash_course_completed hook.
Customizing the Certificate Template
Edit the HTML heredoc inside generate_ld_certificate() in ld_certificates.php. The following variables are available:
| Variable | Description |
|---|---|
$first_name |
Student's first name (escaped) |
$last_name |
Student's last name (escaped) |
$safe_course |
Course name (escaped) |
$completion_date |
Localized completion date |
Customizing the Email
Edit the $subject and $body variables near the end of the function.
Security
- All user-facing output is escaped with
esc_html()to prevent XSS - Post titles are sanitized with
sanitize_text_field() - Email addresses are sanitized with
sanitize_email() kses_remove_filters()is used narrowly aroundwp_insert_post()and immediately restored- Incoming hook data is validated with type checks before use
File Structure
learndash_certificates/
└── ld_certificates.php # Main plugin file — all logic in a single function
License
MIT