vendredi 22 avril 2016

Contact form 7 : how to get custom shortcode datas (checkbox) visible in emails

i need help to display checkbox results from my form in emails. I explain :

I have created custom fields (checkboxes) with ACF for products (woocommerce) and i would like to display them (Front End) if they are checked (in Back end) on a form located on product page. Then i need to get the results (according to what customer has checked) displayed in emails that he receive after submitting the form. I managed to create a custom checkbox shortcode in form and display it in the form, but i never manage to get results in emails...

Here is my codes (i tried 2 solutions):

   // i found this code to get shortcode working in emails but nothing...

         add_filter( 'wpcf7_mail_components', 'dacrosby_do_shortcodes_wpcf7_mail_body', 10, 2 );

         function dacrosby_do_shortcodes_wpcf7_mail_body( $components, $number ) {
            $components['body'] = do_shortcode( $components['body'] );
            return $components;
         };    

         // i tried this solution first, it works to display shortcode on Front end but not in emails

         function wpcf7_pannes_shortcode_handler( $tag ) {
            global $post;

            $values = get_field('pannes');
            $return = '';
         if($values)
         {
            foreach($values as $value)
            {
         $price = get_field('prix_'.$value.'');    
                $return .= '<span class="wpcf7-list-item">';
                $return .= '<input type="checkbox" value="'.$value.'" name="'.$value.'[]"/>';
                $return .= ' <span class="wpcf7-list-item-label">'.$value.'</span>';
                $return .= ' <span class="wpcf7-list-item-price">'.$price.'</span>';
                $return .= '</span>';
            }

         }
         return $return;
         }

          wpcf7_add_shortcode( 'checkboxpannes', 'wpcf7_pannes_shortcode_handler', true ); 

          // then i tried this second solution , but unfortunately it is not working for emails..

          add_action( 'wpcf7_init', 'wpcf7_panne_shortcode' );

         function wpcf7_panne_shortcode() {
            wpcf7_add_shortcode( 'checkbox', 'wpcf7_panne_shortcode_handler' ); 
         }

         function wpcf7_panne_shortcode_handler( $tag ) {
            global $post;

            $values = get_field('pannes');
            $return = '';
         if($values)
         {
            foreach($values as $value)
            {
         $price = get_field('prix_'.$value.'');    
                $return .= '<span class="wpcf7-list-item">';
                $return .= '<input type="checkbox" value="'.$value.'" name="'.$value.'[]"/>';
                $return .= ' <span class="wpcf7-list-item-label">'.$value.'</span>';
                $return .= ' <span class="wpcf7-list-item-price">'.$price.'</span>';
                $return .= '</span>';
            }

         }
         return $return;
         }

The 2 shortcodes i used are [checkboxpannes] and [checkbox panne] in form builder

For emails i have tried everything: [checkboxpannes] [checkbox panne] [panne]...etc

Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire