Last active
February 22, 2024 08:38
-
-
Save wpmudev-sls/f07fb4ecf17332fbb01c38f1274c8473 to your computer and use it in GitHub Desktop.
[Forminator Pro] - Display HTML fields in PDF based on visibility conition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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