参见英文答案 >
Adding an additional custom field in Woocommerce Edit Account page 1个
我正在使用woo-commerce插件在Wordpress中开发一个电子商务网站,我在其中添加了一些注册表单中的其他字段,如手机号码,性别等.如何在我的帐户页面的编辑个人资料中提供这些字段网站由用户编辑. 最佳答案 你可以尝试这个例子,
add_action( 'woocommerce_edit_account_form', 'my_woocommerce_edit_account_form' );
add_action( 'woocommerce_save_account_details', 'my_woocommerce_save_account_details' );
function my_woocommerce_edit_account_form() {
$user_id = get_current_user_id();
$user = get_userdata( $user_id );
if ( !$user )
return;
$twitter = get_user_meta( $user_id, 'twitter', true );
$url = $user->user_url;
?>
<fieldset>
<legend>Social information</legend>
<p>Fill in this information about your social media accounts.</p>
<p class="form-row form-row-thirds">
<label for="twitter">Twitter Username:</label>
<input type="text" name="twitter" value="<?php echo esc_attr( $twitter ); ?>" class="input-text" />
</p>
</fieldset>
<fieldset>
<legend>Additional Information</legend>
<p class="form-row form-row-thirds">
<label for="url">Website:</label>
<input type="text" name="url" value="<?php echo esc_attr( $url ); ?>" class="input-text" />
</p>
</fieldset>
<?php
}
function my_woocommerce_save_account_details( $user_id ) {
update_user_meta( $user_id, 'twitter', htmlentities( $_POST[ 'twitter' ] ) );
$user = wp_update_user( array( 'ID' => $user_id, 'user_url' => esc_url( $_POST[ 'url' ] ) ) );
}
欲获得更多信息,
> Custom User Fields on Woocommerce My Account Page
> Custom WooCommerce User Account Fields
> add user custom field in My Account page in Woocommerce?
希望这会对你有所帮助.