Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save actual-saurabh/939935afc884333526ee4dff34f67f79 to your computer and use it in GitHub Desktop.
Save actual-saurabh/939935afc884333526ee4dff34f67f79 to your computer and use it in GitHub Desktop.
Hide Fields on Checkout Form for Free Access Plans
<?php // Do not copy this line
// Copy from under this line and paste into your child theme's functions.php
add_filter( 'lifterlms_get_person_fields', 'llms_hide_fields_for_free_plans', 10, 2 );
function llms_hide_fields_for_free_plans( $fields, $screen ){
// bail if it isn't the checkout screen
if ( $screen != 'checkout' ){
return $fields;
}
// get the plan ID
$plan_id = filter_input( INPUT_GET, 'plan', FILTER_VALIDATE_INT );
// bail if there's no reliable plan ID
if( empty( $plan_id ) ){
return $fields;
}
// get the access plan object
$plan = new LLMS_Access_Plan( $plan_id );
// see if the plan has free checkout
$free = $plan->has_free_checkout();
// bail if there's no free checkout
if( empty( $free ) ){
return $fields;
}
// loop through fields to hide some of them
foreach( $fields as $array_id=>$field ){
// hide address fields
if( strpos( $field['id'], 'llms_billing_' ) === 0 ){
unset( $fields[$array_id] );
}
/* see https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.person.handler.php
* for all the available fileds that you could hide similarly
*/
//eg, phone. See: https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.person.handler.php#L201
if( strpos( $field['id'], 'llms_phone' ) === 0 ){
unset( $fields[$array_id] );
}
// additional checks here
}
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment