plugins – Save Confirmation Page Title to WPForms Entry

Question

I’m looking for a way to make a snippet that will save the WPForms confirmation page title redirection to the entries.

As the redirection uses wpforms_process_complete hook, I’ve tried :

add_action( 'wpforms_process_complete', function( $fields, $entry, $form_data ) {
    // Get form meta keys
    $form_id = $form_data['id'];
    $form_meta_keys = wpforms()->form->get( $form_id )['meta']['keys'];
  
    // Get entry meta keys
    $entry_meta_keys = ( new WPForms_Entry( $entry['id'] ) )->get_meta_keys();
    
    // Add meta key
    if ( ! in_array( 'titre_confirmation', $entry_meta_keys ) ) {
        wpforms()->entry->update_meta( $entry['id'], 'confirmation_title', '' );
    }
    
    // Get page title
    $confirmation_page_id = $entry['page_id'];
    $confirmation_page_title = get_the_title( $confirmation_page_id );
    
    // Update meta key
    wpforms()->entry->update_meta( $entry['id'], $form_meta_keys['confirmation_title'], $confirmation_page_title );
}, 10, 3 );

Any idea ? Thank you !

0
art_n 4 weeks 2023-05-05T11:49:28-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse