나는 그것을 테스트하고 그 변화를 선택하기 위해 관련 데이터를 전송하지 않습니다, 그냥 추가 아래 선택한 연락처 양식을 출력하기 때문에 (단일 제품 페이지에서) - 투 - 카트 버튼. 또한이 플러그인은 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의 활성 자식 테마 (또는 테마)의 파일이나 간다.
당신은 플러그가 추가 항목 기능과 함께 무엇을하고 있었는지 정확히 얻을 것이다 :
- 사용자 정의 제품명, 메일의 주제로.
- 추가 변형 속성 이름 레이블 + 값 (숨김)입니다. 여기
화면 내 테스트 서버에서 촬영입니다
선택한 속성을 가진 제품 : 나는 양식에 무엇을 얻을
(내가 특별한 텍스트 필드를 숨기 해달라고 jQuery로 끌어온 데이터를 보여줍니다.) :
위의 그림에서 알 수 있듯이, 이메일은 ...
나는 양식의 다른 필드를 제품의 속성을 선택하여 작성하면 내가 얻을이 양식이 이메일 메시지를 전송할 때 : 그래서
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은 예상했던대로 작동하며 이는 작동중인 테스트를 거친 예제 답변입니다.
안녕하세요 LoicTheAztec, 우선 감사드립니다. 나는 모든 단계를 시도하고 따라하지만 양식을 채울 때 나는 메일에 변형을받지 못한다. [text your-product class : product_details]를 모듈 탭에 추가하고 Product : [your-product]를 메일 탭에 추가합니다. – emiliano