Custom signup/registration form fields
This guide explains how to add custom fields to the Sunshine Photo Cart signup form and save the data as customer metadata.
Sunshine Photo Cart provides two action hooks for extending the signup functionality:
sunshine_signup_fields- Add custom fields to the signup formsunshine_after_signup- Process custom field data after successful signup
Here's a complete example adding a "Company Name" field to the signup form:
Adding form fields to the signup form
/**
* Add company name field to signup form
*/
add_action( 'sunshine_signup_fields', 'add_company_signup_field' );
function add_company_signup_field() {
?>
<div class="sunshine--form--field">
<label for="sunshine-signup-company"><?php _e( 'Company Name', 'your-text-domain' ); ?> <span class="sunshine--form--field--desc"><?php _e( 'Optional', 'your-text-domain' ); ?></span></label>
<input type="text" name="sunshine_signup_company" id="sunshine-signup-company" autocomplete="organization" />
</div>
<?php
}
Learn how to add this custom code to your WordPress website
Saving data to customer profile
/**
* Process company name after signup
*/
add_action( 'sunshine_after_signup', 'process_company_signup_field' );
function process_company_signup_field( $customer ) {
// Validate and sanitize the input
if ( ! empty( $_POST['sunshine_signup_company'] ) ) {
$company_name = sanitize_text_field( $_POST['sunshine_signup_company'] );
// Save to customer meta using the customer class method
$customer->update_meta( 'company_name', $company_name );
}
}
Learn how to add this custom code to your WordPress website
Using the customer data
/**
* Get customer company name
*/
$customer = new SPC_Customer( $customer_id );
echo $customer->get_meta( 'company_name' );
Learn how to add this custom code to your WordPress website
Include custom data in customer profile
/**
* Display custom fields in customer profile tab
*/
add_action( 'sunshine_customer_tab_profile', 'display_custom_customer_fields' );
function display_custom_customer_fields( $customer ) {
$company_name = $customer->get_meta( 'company_name' );
if ( $company_name ) {
?>
<h3><?php _e( 'Additional Information', 'your-text-domain' ); ?></h3>
<?php if ( $company_name ) { ?>
<p><strong><?php _e( 'Company:', 'your-text-domain' ); ?></strong> <?php echo esc_html( $company_name ); ?></p>
<?php } ?>
<?php
}
}
Learn how to add this custom code to your WordPress website
Still need help?
If you have not yet found your answer in the documentation articles, please contact support