Action Since 2.4.7 uncanny-continuing-education-credits

learndash_certification_after

Fires after setting certificate pdf data. Fires after certificate PDF data is set, providing access to the TCPDF instance and post ID.

add_action( 'learndash_certification_after', $callback, 10, 1 );

Description

Fires after certificate PDF data has been set and the TCPDF object is ready for further manipulation. Developers can use this hook to add custom content, watermarks, or modify the PDF before it's generated, receiving the TCPDF object and the certificate's post ID.


Usage

add_action( 'learndash_certification_after', 'your_function_name', 10, 1 );

Examples

add_action( 'learndash_certification_after', 'my_learndash_add_custom_text_to_certificate', 10, 2 );

/**
 * Adds custom text to the bottom of a LearnDash certificate PDF.
 *
 * This function is hooked into the 'learndash_certification_after' action,
 * which fires after the main certificate data has been set in the TCPDF object.
 * It demonstrates how to use the provided $pdf object to add additional content.
 *
 * @param TCPDF $pdf     The TCPDF object instance.
 * @param int   $post_id The ID of the certificate post.
 */
function my_learndash_add_custom_text_to_certificate( TCPDF $pdf, int $post_id ) {
    // Example: Add a line of custom text at the bottom of the certificate.
    // You can customize the text, font, color, and position as needed.

    $custom_text = "This certificate is proudly issued by My Awesome Academy.";
    $font_size = 8;
    $text_color = array( 50, 50, 50 ); // Dark grey
    $y_position = $pdf->getPageHeight() - 20; // 20mm from the bottom
    $x_position = $pdf->getOriginalPageWidth() / 2; // Centered horizontally

    // Set font for custom text
    $pdf->SetFont( 'helvetica', '', $font_size );
    $pdf->SetTextColor( $text_color[0], $text_color[1], $text_color[2] );

    // Add the text, centered
    $pdf->SetXY( 0, $y_position ); // Set X to 0 to allow centering with Cell
    $pdf->Cell( 0, 10, $custom_text, 0, 0, 'C', 0, '', 0, false, 'T', 'M' );

    // You could also add other elements here, like:
    // - A link to your website using $pdf->Link()
    // - A watermark using $pdf->Image() with appropriate opacity settings
    // - Conditional text based on the $post_id if you have different certificates
}

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

src/includes/tcpdf-certificate-code.php:672

*
		 * @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 = self::learndash_get_thumb_path( $cert_args['cert_id'] );

		//Only print image if it exists
		if ( ! empty( $img_file ) ) {

Scroll to Top