• Resolved ryanchampniss

    (@ryanchampniss)


    Hi,

    I have a form set up with a dropdown for Country. The dropdown is generated from the post category list. Everything works fine on the site and the data is sent to the post correctly. However, the email I receive displays the category ID, instead of the actual category title. I’m using the Mail(2) to send a confirmation email to people of use the form, so would like the data in there to use the title instead of the ID. Is this doable?

    Thanks,
    Ryan

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    sure this is doable. There are 2 ways to achieve this, either use the Contact Form 7 mail tag filter (‘wpcf7_mail_tag_replaced’ I think, you’ll need to check the CF7 plugin support for that), or you can use my other plugin (The Smart Grid-layout extension for CF7), which was built to overcome the many limitations of the CF7 plugin. It introduces specific mail tag filters and I made a video tutorial on how to use them. You’ll need to get the term name (label) from the the term ID using the WP core function get_term_by

    Thread Starter ryanchampniss

    (@ryanchampniss)

    Excellent! Thank you for that.

    Here is my working code for anyone else experiencing this issue:

    // REPLACE CATEGORY ID WITH FIELD NAME ON EMAILS
    CHANGE your-mail-tag AS APPROPRIATE
    
    add_filter( 'wpcf7_mail_tag_replaced',
     
      function( $replaced, $submitted, $html, $mail_tag ) {
        if ( 'your-mail-tag' == $mail_tag->field_name() ) {
          if ( is_numeric( $submitted ) ) {
            $term_name = get_term( $submitted )->name;
    		$replaced = $term_name;
          }
        }
         return $replaced;
      },
    
      10, 4
    );
    Plugin Author Aurovrata Venet

    (@aurovrata)

    Excellent! Thank you for that.

    wc, do leave a review

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Taxonomy in email’ is closed to new replies.