내 계정에 휴대폰 추가 > 우커머스 계정 편집 필드
내 질문:Woocmerce에서 휴대폰 필드 추가하는 방법my-account/edit-account/
페이지 (관련 템플릿:form-edit-account.php
파일)
다음 답변 스레드와 마찬가지로:
WooCommerce My 계정에 사용자 정의 필드 전화번호 값 저장 > 계정 상세 정보
그러나 이 답변 코드는 일부 후크 함수가 누락되어 있어 불완전합니다.현장 표시를 의미하는 무언가를 완성하기 위해서는 어떤 도움이라도 감사히 받겠습니다.
내 계정 > 계정 편집 페이지에서 사용자 지정 휴대폰 필드를 표시할 수 있는 3가지 옵션이 있습니다.
1) 를 사용하는 첫번째 필드로woocommerce_edit_account_form_start
액션 후크(아래 참조).
2) 기존 필드 후 사용woocommerce_edit_account_form
작업 후크:
// Display the mobile phone field
// add_action( 'woocommerce_edit_account_form_start', 'add_billing_mobile_phone_to_edit_account_form' ); // At start
add_action( 'woocommerce_edit_account_form', 'add_billing_mobile_phone_to_edit_account_form' ); // After existing fields
function add_billing_mobile_phone_to_edit_account_form() {
$user = wp_get_current_user();
?>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="billing_mobile_phone"><?php _e( 'Mobile phone', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--phone input-text" name="billing_mobile_phone" id="billing_mobile_phone" value="<?php echo esc_attr( $user->billing_mobile_phone ); ?>" />
</p>
<?php
}
// Check and validate the mobile phone
add_action( 'woocommerce_save_account_details_errors','billing_mobile_phone_field_validation', 20, 1 );
function billing_mobile_phone_field_validation( $args ){
if ( isset($_POST['billing_mobile_phone']) && empty($_POST['billing_mobile_phone']) )
$args->add( 'error', __( 'Please fill in your Mobile phone', 'woocommerce' ),'');
}
// Save the mobile phone value to user data
add_action( 'woocommerce_save_account_details', 'my_account_saving_billing_mobile_phone', 20, 1 );
function my_account_saving_billing_mobile_phone( $user_id ) {
if( isset($_POST['billing_mobile_phone']) && ! empty($_POST['billing_mobile_phone']) )
update_user_meta( $user_id, 'billing_mobile_phone', sanitize_text_field($_POST['billing_mobile_phone']) );
}
코드가 작동합니다.활성 하위 테마(또는 활성 테마)의 php 파일입니다.테스트를 거쳐 작동합니다.
3) 특정 위치에서 재정의myaccount/form-edit-account.php
템플릿 파일은 이 문서에 설명되어 있듯이 테마를 통해 작성됩니다.그리고 이 답안지에...
이 경우 템플릿에 다음 html 코드를 추가해야 합니다(이 응답 스레드에서와 같이).
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="billing_mobile_phone"><?php _e( 'Mobile phone', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--phone input-text" name="billing_mobile_phone" id="billing_mobile_phone" value="<?php echo esc_attr( $user->billing_mobile_phone ); ?>" />
</p>
이 마지막 경우에는 테마의 기능을 추가해야 합니다.php 파일 섹션 2의 마지막 후크 함수 2개(valid화 및 저장).
언급URL : https://stackoverflow.com/questions/51103458/add-a-mobile-phone-field-on-my-account-edit-account-in-woocommerce
'programing' 카테고리의 다른 글
C에서 좋은 오픈 소스 B-트리 구현은 무엇입니까? (0) | 2023.10.28 |
---|---|
sql이 java programming 'distinct'보다 빠른 경우 (0) | 2023.10.28 |
Internet Explorer(인터넷 익스플로러) 및 jQuery(jQuery)를 사용한 "사용 권한 거부" (0) | 2023.10.23 |
각도 JS 날짜 필터가 작동하지 않습니다. (0) | 2023.10.23 |
MySQL 표준 시간대 (0) | 2023.10.23 |