Add second terms checkbox

Hello @goyals,

Here’s a PHP code that you might find useful (there are three codes to add 3 checkboxes) :

//Box 1 - Required
add_filter(
	'hivepress/v1/forms/user_register',
	function( $form ) {
		  $form['fields']['custom_message_terms_policy'] = [
			'caption' => 'Custom text',
			'type'      => 'checkbox',
			'required' => true,
			'_external' => true,
			'_order'    => 1000,
		];

		return $form;
	},
	1000
);

//Box 2 - Required
add_filter(
	'hivepress/v1/forms/user_register',
	function( $form ) {
//For "Customtext" below, use the same words as in "caption" but without the spaces between the words. If you write "lorem ipsum dolor sit amet", you should write "loremipsumdolorsitamet".
		$form['fields']['customtext'] = [
			'caption' => 'Custom text.', 
			'type'    => 'checkbox',
			'required' => true,			
			'_order'  => 123,
		];

		return $form;
	},
  1000
);

//Box 3 - Required
add_action(
	'hivepress/v1/models/user/register',
	function( $user_id, $values ) {
		if(isset($values['_terms'])){
			update_user_meta($user_id, 'hp_registration_terms_accepted', true);
		}
		
		if(isset($values['custom_message_terms_policy'])){
			update_user_meta($user_id, 'hp_registration_policy_accepted', true);
		}
		
	},
	10, 
	2
);

Here is a PHP code that you can implement with Code Snippets – WordPress plugin | WordPress.org

See the tutorial : How to add custom code snippets - HivePress Help Center

This PHP code is based on the following code : Add a custom checkbox to the user registration form - Gist.github.com

This code allows you to have three obligatory boxes for the user. If you don’t want the checkbox to be required, you can delete : ‘required’ => true,

You can also add a URL in “Custom text” with :

'caption' => 'Custom text <a href="https://www.your custom url" target="_blank">Custom text</a>',

You can find another similar discussion here : Force new users to accept terms AND privacy policy? - General - HivePress Community

I hope you find it useful.

1 Like