Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/f07fb4ecf17332fbb01c38f1274c8473 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/f07fb4ecf17332fbb01c38f1274c8473 to your computer and use it in GitHub Desktop.
[Forminator Pro] - Display HTML fields in PDF based on visibility conition
<?php
/**
* Plugin Name: [Forminator Pro] Display HTML fields in PDF baed on visibility conditions
* Description: Display HTML fields in PDF baed on visibility conditions
* Author: Prashant @ WPMUDEV
* Task: SLS-5783
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
add_action( 'forminator_custom_form_mail_before_send_mail', 'wpmudev_check_hidden_html_fields', 10, 4 );
function wpmudev_check_hidden_html_fields( $cls, $custom_form, $data, $entry ) {
if ( 1645 != $custom_form->id ) { // Please change the form ID.
return;
}
$hidden_fields = Forminator_CForm_Front_Action::$hidden_fields;
foreach ( $hidden_fields as $key => $value ) {
if ( false !== strpos( $value, 'html-' ) ) {
$GLOBALS['html_vals'][] = forminator_replace_form_data( '{' . $value . '}', $custom_form, $entry, true );
}
}
}
add_filter( 'forminator_pdf_basic_template_markup', function( $html, $pdf_settings, $form_id, $entry_id ) {
if ( 1645 != $form_id ) { // Please change the form ID.
return $html;
}
if ( ! empty( $GLOBALS['html_vals'] ) ) {
foreach ( $GLOBALS['html_vals'] as $key => $value ) {
if ( ! empty( $value ) ) {
$value = str_replace( '<strong>-</strong> ', '<strong>-</strong> ', $value );
$value = str_replace( ' €', ' €', $value );
$html = str_replace( $value, '', $html );
}
}
}
return $html;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment