2017-02-10 2 views
4

WooCommerce를 사용하면 문의 양식 7 및 Product Info Request 플러그인을 사용하여 단일 제품 페이지 내에 양식을 추가 할 수 있습니다. 사용자가 문의 요청을 보낼 수있는 기능이 필요하기 때문에 제품 (간단한 문의 양식).선택한 제품 변형 데이터를 문의 양식 7에 첨부하십시오. 문의 양식

이 스크린 샷을보고 이해할 수 :

screeshot

내 모든 제품은 변화와 변수 제품입니다 (속성에서).

고객이 선택한 유사 콘텐츠를 검색하고 문의 양식 7을 통해 보낼 수있는 방법이 있습니까?

예를 들어

:

사용자가 다음 양식을 작성, 검은 색 및 크기의 색상을 선택하고 이메일 때 고전적인 정보를 수신 할뿐만 아니라, 전송 (이름, 이메일 ECC를 ..) 또한 수신

감사 (이 경우 blacks으로) 선택한 속성.

+0

안녕하세요 LoicTheAztec, 우선 감사드립니다. 나는 모든 단계를 시도하고 따라하지만 양식을 채울 때 나는 메일에 변형을받지 못한다. [text your-product class : product_details]를 모듈 탭에 추가하고 Product : [your-product]를 메일 탭에 추가합니다. – emiliano

답변

2

업데이트 :추가 WC 3+ 호환성

나는 그것을 테스트하고 그 변화를 선택하기 위해 관련 데이터를 전송하지 않습니다, 그냥 추가 아래 선택한 연락처 양식을 출력하기 때문에 (단일 제품 페이지에서) - 투 - 카트 버튼. 또한이 플러그인은 2 년 이상 업데이트되지 않았으므로 구식입니다.

선한 NEW : 그것은 제품의 탭에 문의 양식 7 단축 코드를 설정하는 방법에 대해 설명합니다 Product Name WooCommerce in Contact Form 7

:이 관련 답을 발견

작업 솔루션 선택한 제품 제목을 이메일에 표시합니다.

그래서이 대답에서 코드를 바꿔서 플러그인을 사용하는 것처럼 사용했습니다 (장바구니 버튼에 추가). ColorSize: 여기 내 변수 제품에서 제품의 변화에 ​​대한 2 개 속성을 설정 한 예/대답

. 나는이 텍스트 필드 [text your-product class:product_details]를 추가해야 다음

<label> Your Name (required) 
    [text* your-name] </label> 

<label> Your Email (required) 
    [email* your-email] </label> 

<label> Subject (required) 
    [text* your-subject class:product_name] </label> 

<label> Your Message 
    [textarea your-message] </label> 

[submit "Send"] 

[text your-product class:product_details] 

:

이 내 설정 내 코드에서 사용하는 양식 Contact form 7 있습니다.그래서 당신은 당신의 전자 우편에 그것을 얻으려면, "메시지 본문"내부에 "메일"설정 탭도 [your-product] 태그를 추가해야합니다

From: [your-name] <[your-email]> 
Subject: [your-subject] 

Product: [your-product] 

Message Body: 
[your-message] 

-------------- 
This e-mail was sent from a contact form 7 

PHP 코드 사용자 정의 연료 소모량이 woocommerce_after_add_to_cart_form 행동에 중독 훅 :

add_action('woocommerce_after_add_to_cart_form', 'product_enquiry_custom_form'); 
function product_enquiry_custom_form() { 

    global $product, $post; 

    // Set HERE your Contact Form 7 shortcode: 
    $contact_form_shortcode = '[contact-form-7 id="382" title="form"]'; 

    // compatibility with WC +3 
    $product_id = method_exists($product, 'get_id') ? $product->get_id() : $product->id; 
    $product_title = $post->post_title; 

    // The email subject for the "Subject Field" 
    $email_subject = __('Enquire about', 'woocommerce') . ' ' . $product_title; 

    foreach($product->get_available_variations() as $variation){ 
     $variation_id = $variation['variation_id']; 
     foreach($variation['attributes'] as $key => $value){ 
      $key = ucfirst(str_replace('attribute_pa_', '', $key)); 
      $variations_attributes[$variation_id][$key] = $value; 
     } 
    } 
    // Just for testing the output of $variations_attributes 
    // echo '<pre>'; print_r($variations_attributes); echo '</pre>'; 


    ## CSS INJECTED RULES ## (You can also remve this and add the CSS to the style.css file of your theme 
    ?> 
    <style> 
     .wpcf7-form-control-wrap.your-product{ opacity:0;width:0px;height:0px;overflow: hidden;display:block;margin:0;padding:0;} 
    </style> 

    <?php 


    // Displaying the title for the form (optional) 
    echo '<h3>'.$email_subject.'</h3><br> 
     <div class="enquiry-form">' . do_shortcode($contact_form_shortcode) . '</div>'; 


    ## THE JQUERY SCRIPT ## 
    ?> 
    <script> 
     (function($){ 

      <?php 
       // Passing the product variations attributes array to javascript 
       $js_array = json_encode($variations_attributes); 
       echo 'var $variationsAttributes = '. $js_array ; 
      ?> 

      // Displaying the subject in the subject field 
      $('.product_name').val('<?php echo $email_subject; ?>'); 

      ////////// ATTRIBUTES VARIATIONS SECTION /////////// 

      var $attributes; 

      $('td.value select').blur(function() { 
       var $variationId = $('input[name="variation_id"]').val(); 
       // console.log('variationId: '+$variationId); 
       if (typeof $variationId !== 'undefined'){ 
        for(key in $variationsAttributes){ 
         if(key == $variationId){ 
          $attributes = $variationsAttributes[key]; 
          break; 
         } 
        } 

       } 
       if (typeof $attributes !== 'undefined'){ 
        // console.log('Attributes: '+JSON.stringify($attributes)); 
        var $attributesString = ''; 
        for(var attrKey in $attributes){ 
         $attributesString += ' ' + attrKey + ': ' + $attributes[attrKey] + ' — '; 
        } 
        $('.product_details').val('Product <?php echo $product_title; ?> (ID <?php echo $product_id; ?>): ' + $attributesString); 
       } 
      }); 

     })(jQuery); 
    </script> 

    <?php 
} 

코드는 어떤 플러그인 파일도 function.php의 활성 자식 테마 (또는 테마)의 파일이나 간다.

당신은 플러그가 추가 항목 기능과 함께 무엇을하고 있었는지 정확히 얻을 것이다 :

  • 사용자 정의 제품명, 메일의 주제로.
  • 추가 변형 속성 이름 레이블 + 값 (숨김)입니다. 여기

화면 내 테스트 서버에서 촬영입니다

선택한 속성을 가진 제품 : 나는 양식에 무엇을 얻을 enter image description here

(내가 특별한 텍스트 필드를 숨기 해달라고 jQuery로 끌어온 데이터를 보여줍니다.) : enter image description here

위의 그림에서 알 수 있듯이, 이메일은 ...

나는 양식의 다른 필드를 제품의 속성을 선택하여 작성하면 내가 얻을이 양식이 이메일 메시지를 전송할 때 : 그래서

From: John Smith <[email protected]> 
Subject: Enquire about Ship Your Idea 

Product: Product Ship Your Idea (ID 40): Color: black — Size: 12 — 

Message Body: 
I send this request about this very nice product … I send this request about this very nice product … 

-- 
This e-mail was sent from a contact form 7 

을 everithing은 예상했던대로 작동하며 이는 작동중인 테스트를 거친 예제 답변입니다.