teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

新規追加ではなく編集に変更

2021/01/18 05:41

投稿

thinkmad83989
thinkmad83989

スコア6

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,48 @@
1
- Wordpressにてユーザー情報項目の新規追加をしたいです。
1
+ Wordpressにてユーザー情報項目の編集をしたいです。
2
- WooCommerce用してオーダーメイド靴を売っているのですが、ユーザーが自分サイズwordpress上に登録できるようにしたいです。
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
+ ```