Action
Since 2.4.7
uncanny-automator-pro
learndash_certification_after
Fires after setting certificate pdf data. Fires after setting certificate PDF data, providing access to the TCPDF instance and post ID.
add_action( 'learndash_certification_after', $callback, 10, 1 );
Description
Fires after certificate PDF data is generated, providing access to the TCPDF object and the certificate post ID. Developers can use this hook to further customize the PDF, such as adding watermarks, modifying page settings, or embedding additional content, before it's finalized.
Usage
add_action( 'learndash_certification_after', 'your_function_name', 10, 1 );
Examples
add_action( 'learndash_certification_after', 'my_learndash_custom_certificate_footer', 10, 2 );
/**
* Adds a custom footer to LearnDash certificates after they are generated.
*
* @param TCPDF $pdf The TCPDF instance for the certificate.
* @param int $post_id The ID of the certificate post.
*/
function my_learndash_custom_certificate_footer( TCPDF $pdf, int $post_id ) {
// Get the current user ID.
$user_id = get_current_user_id();
// If we are not logged in or the user ID is 0, do nothing.
if ( ! $user_id ) {
return;
}
// Get some user-specific data (e.g., username).
$user_info = get_userdata( $user_id );
$username = $user_info->display_name;
// Define the footer text.
$footer_text = sprintf(
__( 'Generated for %s on %s', 'my-text-domain' ),
$username,
date_i18n( get_option( 'date_format' ) )
);
// Set the footer font.
$pdf->SetFont( 'helvetica', 'I', 8 );
// Get the page width.
$page_width = $pdf->getPageWidth();
// Set the position for the footer.
// Position is relative to the bottom of the page (mm units).
$footer_y_position = $pdf->getBreakMargin() - 3; // Slightly above the standard bottom margin.
$pdf->setY( $footer_y_position );
// Write the footer text, centered.
$pdf->Cell( 0, 10, $footer_text, 0, false, 'C', 0, '', 0, false, 'T', 'M' );
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/learndash/helpers/learndash-pro-helpers.php:1108
* Fires after setting certificate pdf data.
*
* @param TCPDF $pdf `TCPDF` class instance.
* @param int $post_id Post ID.
*
* @since 2.4.7
*/
do_action( 'learndash_certification_after', $pdf, $cert_args['cert_id'] );
// get featured image
$img_file = $this->learndash_get_thumb_path( $cert_args['cert_id'] );
//Only print image if it exists
if ( ! empty( $img_file ) ) {