• Resolved GregW

    (@gwmbox)


    Is it possible to add a shortcode in the email sent? If not will this be available in a future update? I note it has been a year since an update.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Tobias Zimpel

    (@tz-media)

    Hi gwmbox,

    no this isn’t yet possible, but I‘m actually working on it. But as an intermediate solution I can provide you with a code snippet that will allow you to add a specific shortcode to the email. What shortcode(s) do you need?

    Best regards
    Tobias

    • This reply was modified 5 years, 11 months ago by Tobias Zimpel.
    Thread Starter GregW

    (@gwmbox)

    Basic items like display name, nothing too fancy.

    It is not super urgent so I will eagerly await your update ??

    Plugin Author Tobias Zimpel

    (@tz-media)

    OK. But I don’t have a real timeline, as I’m quite busy at the moment, and this is a little more complex. It actually needs configuration options for users to configure surrogate shortcodes to use in the email templates that are mapped to the real shortcode.

    If this becomes urgent for you, just ping me and we’ll find a workaround. This is actually quite easy to achieve.

    Thread Starter GregW

    (@gwmbox)

    Thanks. If you can give me a sample code for say showing display_name, I can then most likely adjust it for my needs for other shortcodes I need.

    Plugin Author Tobias Zimpel

    (@tz-media)

    Sure, here’s some example code:

    function my_special_mail_tag( $output, $name, $html ) {
    	if ( 'my_surrogate_shortcode' == $name )
    		$output = do_shortcode( '[real_shortcode attribute="value"]' );
     
    	return $output;
    }
    add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );

    When you enter [my_surrogate_shortcode] into your email template, the real shortcode [real_shortcode attribute="value"] is executed instead, and the result is printed in the email.

    You can either add this code to your functions.php (if you use a child theme), or in a custom plugin like this (prepared for multiple shortcodes as an example).

    <?php
    /**
     * Plugin Name: My custom shortcodes for Contact Form 7
     */
    
    function my_special_mail_tag( $output, $name, $html ) {
    	if ( 'my_surrogate_shortcode' == $name )
    		$output = do_shortcode( '[real_shortcode attribute="value"]' );
    
            if ( 'my_other_surrogate_shortcode' == $name )
    		$output = do_shortcode( '[other_real_shortcode]' );
     
    	return $output;
    }
    add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );
    
    Thread Starter GregW

    (@gwmbox)

    Awesome, thanks ??

    Can you explain me why this code doesn’t work for me?

    function get_acf_field(){
        $output = get_field( 'lienvideo' );
        return $output;
    }
    add_shortcode( 'myvideo', 'get_acf_field' );
    
    function my_special_mail_tag( $output, $name, $html ) {
        if ( 'my_surrogate_shortcode' == $name )
            $output = do_shortcode( '[myvideo]' );
     
        return $output;
    }
    add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );

    If I put [myvideo] in my template form I got the value of my shortcode, but when I put [my_surrogate_shortcode] I the mail template I got nothing.

    Please help me.

    I finaly got it!!
    I wanted to return an ACF field value with the [acf field=”value”] shortcode.
    But to work I needed to pass the post id too.

    If anybody have the same problem, that’s my final code to get an ACF field in the email template.

    add_filter( 'wpcf7_special_mail_tags', 'your_special_mail_tag', 10, 3 );
    function your_special_mail_tag( $output, $name, $html ) {
        if ( 'myvideo' == $name )
            $output = do_shortcode( '[acf field="myvideolink" post_id="233"]' );
    
        return $output;
    }
    Plugin Author Tobias Zimpel

    (@tz-media)

    Great that you got it to work for you, and thank you for the example for others.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Working in message’ is closed to new replies.