質問編集履歴
1
新規追加ではなく編集に変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,48 @@
|
|
1
|
-
Wordpressにてユーザー情報項目の
|
1
|
+
Wordpressにてユーザー情報項目の編集をしたいです。
|
2
|
-
|
2
|
+
woocommerceを使用しているのですが、マイアカウントのアカウント詳細内の項目を追加したいです。
|
3
|
+
具体的には下記サイトを参考に、項目を追加することはできたのですが、テキストボックスを名前の入力欄のように左右2つ置くことができていません。
|
3
|
-
|
4
|
+
もともとある姓名欄はclassをあててサイズを変えていると思うのですが、どの部分に追加すればよいか分かりません。
|
5
|
+
https://rudrastyh.com/woocommerce/edit-account-fields.html
|
4
6
|
|
7
|
+
```ここに言語を入力
|
8
|
+
/**
|
9
|
+
* Step 1. Add your field
|
10
|
+
*/
|
11
|
+
add_action( 'woocommerce_edit_account_form', 'misha_add_field_edit_account_form' );
|
12
|
+
// or add_action( 'woocommerce_edit_account_form_start', 'misha_add_field_edit_account_form' );
|
13
|
+
function misha_add_field_edit_account_form() {
|
14
|
+
|
15
|
+
woocommerce_form_field(
|
16
|
+
'country_to_visit',
|
17
|
+
array(
|
18
|
+
'type' => 'text',
|
19
|
+
'required' => true, // remember, this doesn't make the field required, just adds an "*"
|
20
|
+
'label' => 'Country you want to visit the most',
|
21
|
+
'description' => 'Maybe it is Norway or New Zealand or...?',
|
22
|
+
),
|
23
|
+
get_user_meta( get_current_user_id(), 'country_to_visit', true ) // get the data
|
24
|
+
);
|
25
|
+
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Step 2. Save field value
|
30
|
+
*/
|
31
|
+
add_action( 'woocommerce_save_account_details', 'misha_save_account_details' );
|
32
|
+
function misha_save_account_details( $user_id ) {
|
33
|
+
|
34
|
+
update_user_meta( $user_id, 'country_to_visit', sanitize_text_field( $_POST['country_to_visit'] ) );
|
35
|
+
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Step 3. Make it required
|
40
|
+
*/
|
41
|
+
add_filter('woocommerce_save_account_details_required_fields', 'misha_make_field_required');
|
5
|
-
|
42
|
+
function misha_make_field_required( $required_fields ){
|
43
|
+
|
44
|
+
$required_fields['country_to_visit'] = 'Country you want to visit the most';
|
45
|
+
return $required_fields;
|
46
|
+
|
47
|
+
}
|
48
|
+
```
|