Support » Plugin: Contact Form 7 Shortcode Enabler » shortcode in email body w/ parameters atts

  • Resolved gaucho code

    (@glowzar)


    Hey guys, how can I make my contact form auto-reply emails to contain a custom shortcode that shows a template? this shortcode works on normal wordpress pages, but doesn’t work on CF7 email template., not even using this plugin.

    this is my shortcode declared on functions.php

    
    function sc_mostrarcursos($atts, $content = null) {
        extract(shortcode_atts(array(
                "id" => '1',
        ), $atts));
        global $post;
      
      $postargs = array(
        'post_type'=> 'product',
        'order'=> 'DESC',
        'post_type' => 'product',
        'posts_per_page' => 1,
        'post__in'=> array($id)
      );  
      $myposts = get_posts($postargs);
      
      $retour='<ul>';
        foreach($myposts as $post) :
                setup_postdata($post);
           
                $retour.= get_template_part('template_curso');
    
            endforeach;
        $retour.='</ul> ';
        return $retour;
    }
    add_shortcode("mostrarcursos", "sc_mostrarcursos");

    and this how I’m rendering it, no success… emails arrive with the plain shortcode.

    [mostrarcursos id=”5240″]

    I checked the link shared, but there is not clue on how to put some parameters – atts from the shortcode dynamically… any hints???

    The solution Solution – using wpcf7_special_mail_tags filter is not working for me.

    • This topic was modified 2 years, 7 months ago by gaucho code.
Viewing 1 replies (of 1 total)
  • Plugin Author Tobias Zimpel

    (@tz-media)

    Hi, sorry for the late response. Main problem here is that shortcodes with attributes don’t work in email templates. So with the following you can use [mostracursos_5204] in the email template to trigger the [mostrarcursos id=”5240″] shortcode:

    function my_special_mail_tag( $output, $name, $html ) {
    	if ( 'mostracursos_5204' == $name )
    		$output = do_shortcode( '[mostrarcursos id=”5240″]' );
     
    	return $output;
    }
    add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );

    If you need the shortcode also with other id values, you need to repeat the whole code block with the new id in both places.

    Does that help?

Viewing 1 replies (of 1 total)
  • The topic ‘shortcode in email body w/ parameters atts’ is closed to new replies.