Woocommerce 저장소의 체크 아웃 페이지에 사용자 지정 필드를 추가했습니다. 필드는 '식당 위치'입니다. 고객이 주문할 때 나의 목표는 '식당 위치'필드를 사용하여 주문 확인을 보낼 이메일을 결정하는 것입니다.전자 메일 수신자가 WooCommerce의 사용자 지정 필드 값을 기반으로합니다.
다음은 맞춤 입력란을 정의한 방법입니다.
/////// Hook custom field in ///////
add_filter('woocommerce_checkout_fields', 'custom_checkout_fields');
function custom_checkout_fields($fields) {
$fields['order']['restaurant_location'] = array(
'label' => __('Food options', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => true,
'clear' => false,
'type' => 'select',
'options' => array(
'no' => __('New Orleans', 'woocommerce'),
'br' => __('Baton Rouge', 'woocommerce')
)
);
return $fields;
}
이메일 필터를 사용해 보았습니다. 이메일 필터가 작동
add_filter('woocommerce_email_recipient_new_order', 'gon_conditional_email_recipient', 10, 2);
function gon_conditional_email_recipient($recipient, $order) {
$gon_order_data = $order->get_data();
$gon_restaurant_location = $gon_order_data['order']['restaurant_location'];
if ( $gon_restaurant_location == 'New Orleans') {
$recipient = '[email protected]';
return $recipient;
}
else if ( $gon_restaurant_location == 'Baton Rouge') {
$recipient = '[email protected]';
return $recipient;
}
return $recipient;
}
, 즉 나도 주소로 가서 이메일을 얻을 수 있습니다,하지만 난 제대로 '$gon_restaurant_location
'변수에 끌어 수없는 것. 어떤 아이디어?
감사합니다,
피코
. CRUD 메소드와의 호환성을 위해'woocommerce_checkout_create_order'로 전환하는 것이 좋습니다. – helgatheviking
@helgatheviking 좋은 제안 +1 ... WooCommerce 직원이 체크 아웃 필드 문서를 업데이트해야합니다 ... 'get_post_meta ($ order-> id')와 같은 나머지 오류가 있습니다. – LoicTheAztec