모든 WooCommerce 체크아웃 필드에 대한 사용자 지정 자리 표시자
WooCommerce 체크아웃 필드에 플레이스홀더를 추가하려고 하는데 전화기와 이메일 필드를 제외한 모든 필드에서 완벽하게 작동합니다.
사용하고 있는 코드는 다음과 같습니다.
add_filter('woocommerce_default_address_fields', 'override_address_fields');
function override_address_fields( $address_fields ) {
$address_fields['first_name']['placeholder'] = 'Fornavn';
$address_fields['last_name']['placeholder'] = 'Efternavn';
$address_fields['address_1']['placeholder'] = 'Adresse';
$address_fields['state']['placeholder'] = 'Stat';
$address_fields['postcode']['placeholder'] = 'Postnummer';
$address_fields['city']['placeholder'] = 'By';
$address_fields['phone']['placeholder'] = 'Telefon';
$address_fields['email']['placeholder'] = 'Email';
return $address_fields;
}
내가 어디가 잘못됐지?왜 전화와 이메일이 결과를 내지 않는 거죠?
브라우저 개발자 도구 검사기를 사용하여 두 필드의 ID를 가져왔습니다.
편집:
또한 다음과 같은 권장 코드를 사용해 보았습니다.
add_filter('woocommerce_checkout_fields', 'override_checkout_fields');
function override_checkout_fields( $checkout_fields ) {
$checkout_fields['first_name']['placeholder'] = 'Fornavn';
$checkout_fields['last_name']['placeholder'] = 'Efternavn';
$checkout_fields['address_1']['placeholder'] = 'Adresse';
$checkout_fields['state']['placeholder'] = 'Stat';
$checkout_fields['postcode']['placeholder'] = 'Postnummer';
$checkout_fields['city']['placeholder'] = 'By';
$checkout_fields['phone']['placeholder'] = 'Telefon';
$checkout_fields['email']['placeholder'] = 'Email';
return $checkout_fields;
}
그리고 이것도.
add_filter('woocommerce_checkout_fields', 'override_checkout_fields');
function override_checkout_fields( $checkout_fields ) {
$checkout_fields['billing_first_name']['placeholder'] = 'Fornavn';
$checkout_fields['billing_last_name']['placeholder'] = 'Efternavn';
$checkout_fields['billing_address_1']['placeholder'] = 'Adresse';
$checkout_fields['billing_state']['placeholder'] = 'Stat';
$checkout_fields['billing_postcode']['placeholder'] = 'Postnummer';
$checkout_fields['billing_city']['placeholder'] = 'By';
$checkout_fields['billing_phone']['placeholder'] = 'Telefon';
$checkout_fields['billing_email']['placeholder'] = 'Email';
return $checkout_fields;
}
하지만 효과가 없어요.
공식 문서를 보면, 이 문서에는 'phone'그리고.'email'필터 후크를 사용할 때 기본 주소의 키 필드를 지정합니다.
허용되는 필드 키는 다음과 같습니다.
country,first_name,last_name,company,address_1,address_2,city,state,postcode.
이 때문에, 다음의 방법으로 변경을 취득할 수 있습니다.
전자 메일과 전화는 과금 필드이며 필터 후크를 통해 사용할 수 있습니다.이름이 붙여져 있습니다(매뉴얼 참조).'billing_phone'그리고.'billing_phone'…
올바른 덮어쓰기 방법은 다음과 같습니다.
add_filter( 'woocommerce_checkout_fields' , 'override_billing_checkout_fields', 20, 1 );
function override_billing_checkout_fields( $fields ) {
$fields['billing']['billing_phone']['placeholder'] = 'Telefon';
$fields['billing']['billing_email']['placeholder'] = 'Email';
return $fields;
}
기타 필드(청구 및 배송):
add_filter('woocommerce_default_address_fields', 'override_default_address_checkout_fields', 20, 1);
function override_default_address_checkout_fields( $address_fields ) {
$address_fields['first_name']['placeholder'] = 'Fornavn';
$address_fields['last_name']['placeholder'] = 'Efternavn';
$address_fields['address_1']['placeholder'] = 'Adresse';
$address_fields['state']['placeholder'] = 'Stat';
$address_fields['postcode']['placeholder'] = 'Postnummer';
$address_fields['city']['placeholder'] = 'By';
return $address_fields;
}
코드가 기능합니다.php 파일 또는 임의의 플러그인 파일에 있는 활성 자식 테마(또는 테마)입니다.
모든 코드는 Woocommerce 3+로 테스트되어 동작합니다.
레퍼런스:수행 및 필터를 사용하여 체크아웃 필드 사용자 정의
로그인 폼필드의 경우:WooCommerce 로그인 폼 사용자 필드 맞춤
공식 문서 https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/에 따르면 업데이트된 코드가 여기에 있습니다.
add_filter( 'woocommerce_checkout_fields' , 'override_billing_checkout_fields', 20, 1 );
function override_billing_checkout_fields( $fields ) {
$fields['billing']['billing_first_name']['placeholder'] = 'Prénom';
$fields['billing']['billing_last_name']['placeholder'] = 'Nom';
$fields['billing']['billing_company']['placeholder'] = 'Nom de la société (optionnel)';
$fields['billing']['billing_postcode']['placeholder'] = 'Code postal';
$fields['billing']['billing_phone']['placeholder'] = 'Téléphone';
$fields['billing']['billing_city']['placeholder'] = 'Ville';
$fields['shipping']['shipping_first_name']['placeholder'] = 'Prénom';
$fields['shipping']['shipping_last_name']['placeholder'] = 'Nom';
$fields['shipping']['shipping_company']['placeholder'] = 'Nom de la société (optionnel)';
$fields['shipping']['shipping_postcode']['placeholder'] = 'Code postal';
$fields['shipping']['shipping_phone']['placeholder'] = 'Téléphone';
$fields['shipping']['shipping_city']['placeholder'] = 'Ville';
return $fields;
}
결과:
WooCommerce 매뉴얼을 참조하면 다음 웹 사이트를 사용해 볼 수 있습니다.woocommerce_checkout_fields대신 필터링하다woocommerce_default_address_fields
위의 필드가 모두 주소에 관련된 것은 아니며, 후크는 에서 파생되었기 때문에 보다 논리적으로 보입니다.class-wc-countries.php.
또한 필드 이름은 페이지 컨텍스트에 따라 다릅니다.예를 들어 과금 페이지필드의 이름은 다음과 같습니다.
- billing_first_name
- billing_last_name
- 과금_이메일
- 과금_전화
도움이 됐으면 좋겠네요!행운을 빌어요.
언급URL : https://stackoverflow.com/questions/46326620/custom-placeholder-for-all-woocommerce-checkout-fields
'programing' 카테고리의 다른 글
| 사용자 역할에 따른 AngularJS, ui.router, 로드 템플릿 및 컨트롤러 (0) | 2023.03.05 |
|---|---|
| 스프링 부트에서 다양한 유형의 ResponseEntity를 반환하는 가장 좋은 방법(스프링에서의 REST 오류 처리) (0) | 2023.03.05 |
| get_template_directory_uri()는 SSL 사이트에서 https 대신 http를 반환합니다. (0) | 2023.03.05 |
| 표시를 거부했습니다.....frame-flashing https://www.facebook.com (0) | 2023.03.05 |
| 외부 설정 방법jQuery를 사용한HTML (0) | 2023.03.05 |