Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save travislopes/687b10d58f3d5208be925369399b8496 to your computer and use it in GitHub Desktop.
Save travislopes/687b10d58f3d5208be925369399b8496 to your computer and use it in GitHub Desktop.
/**
* Custom account fields
*/
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;
$height = get_user_meta( $user_id, 'height', true );
$waist = get_user_meta( $user_id, 'waist', true );
$shoesize = get_user_meta( $user_id, 'shoesize', true );
?>
<fieldset>
<legend>Measurements</legend>
<label for="height">Height (in inches):</label><p><?php echo esc_attr( $height ); ?></p>
<label for="height">Waist size (in inches):</label><p><?php echo esc_attr( $waist ); ?></p>
<p>Fill out basic measurements to be calculated for custom fitting.</p>
<p class="form-row form-row-thirds">
<label for="height">Height (in inches):</label>
<input type="text" name="height" value="<?php echo esc_attr( $height ); ?>" class="input-text" />
</p>
<p class="form-row form-row-thirds">
<label for="waist">Waist size (in inches):</label>
<input type="text" name="waist" value="<?php echo esc_attr( $waist ); ?>" class="input-text" />
</p>
<p class="form-row form-row-thirds">
<label for="shoesize">Shoe size:</label>
<input type="text" name="shoesize" value="<?php echo esc_attr( $shoesize ); ?>" class="input-text" />
</p>
</fieldset>
<?php
}
function my_woocommerce_save_account_details( $user_id ) {
update_user_meta( $user_id, 'height', htmlentities( $_POST[ 'height' ] ) );
update_user_meta( $user_id, 'waist', htmlentities( $_POST[ 'waist' ] ) );
update_user_meta( $user_id, 'shoesize', htmlentities( $_POST[ 'shoesize' ] ) );
}
add_filter( 'gform_field_value_account_measurements', 'my_custom_population_function' );
function my_custom_population_function() {
$user_id = get_current_user_id();
$user = get_userdata( $user_id );
if ( !$user )
return;
$height = get_user_meta( $user_id, 'height', true );
$waist = get_user_meta( $user_id, 'waist', true );
$shoesize = get_user_meta( $user_id, 'shoesize', true );
$measurements = '<p>' . esc_html( $height ) . '</p>;
$measurements .= '<p>' . esc_html( $waist ) . '</p>;
$measurements .= '<p>' . esc_html( $shoesize ) . '</p>;
return $measurements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment