• Resolved MikepFive

    (@mikepfive)


    Hi,

    I’ve used Contact From 7 in several sites – and think its excellent.

    I’ve got a particular requirement to add a ‘custom’ short code to the email (actually to uses IP address to track country – but that’s only my particular use)

    I’ve used the following to facilitate custom shortcodes in forms:

    add_filter( ‘wpcf7_form_elements’, ‘mycustom_wpcf7_form_elements’ );

    function mycustom_wpcf7_form_elements( $form ) {
    $form = do_shortcode( $form );

    return $form;
    }

    but can’t find a way to do the same thing in the email template (and have resorted to editing ‘special-mail-tags.php’ to achieve what I need to do – but that’s not very elegant or easy to maintain)

    Is there a better way to use custom shortcodes in email output from Contact Form 7 ?

    regards,

    Mike

    https://www.ads-software.com/extend/plugins/contact-form-7/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Special Mail Tags

    You can get IP address by using [_remote_ip] in mail content.

    Thread Starter MikepFive

    (@mikepfive)

    Takayuki,

    thanks for getting back to me so promptly.

    I know that I can get IP address by using [_remote_ip] in mail content – I actually use it – but I also want to lookup the Country that the address relates to, so I use the Quick Flag plugin, which also gives me a nice graphic image of the National Flag!

    For the moment I’ve simply added:

    elseif ( ‘quick-flag’ == $name )
    $output = do_shortcode(‘[quick-flag]’);

    to the end of the function wpcf7_special_mail_tag_for_post_data() in the special-mail-tags.php file to achieve what I want – but would prefer a better solution that won’t break when I update Contact Form 7.

    Thanks for your help with this – and for a great plugin.

    Mike

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    Try this:

    add_filter( 'wpcf7_special_mail_tags', 'your_special_mail_tag', 10, 3 );
    
    function your_special_mail_tag( $output, $name, $html ) {
    	if ( 'quick-flag' == $name )
    		$output = do_shortcode( '[quick-flag]' );
    
    	return $output;
    }

    Place [quick-flag] where you wish the flag.

    Thread Starter MikepFive

    (@mikepfive)

    Takayuki,

    brilliant !!

    Works a treat.

    I’m very grateful for A) a GREAT plugin B) an EXCELLENT solution C) the SPEED and QUALITY of your support

    I’m in your debt

    Many thanks

    Mike

    good day ,
    thank you for the solution u mentioned in this post .
    i’ve tried it but seems sth goes wrong in my recipient email .

    User IP :60.53.86.128

    IP Location : Malaysia (<img class=”quick-flag” title=”Malaysia” src=”https://www.nicollo.com/wp-content/plugins/quick-flag/img/flags/MY.gif&#8221; />)

    any idea why the flag cant be shown in email

    Thank You

    I want to do something very similar but I want to pass my shortcode one of the cf7 variables. How do I get those in my function?

    @ikawares & @tim Berneman: If you require assistance then, as per the Forum Welcome, please post your own topic.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom shortcode in emails’ is closed to new replies.