LLMS_Forms::get_free_enroll_form_fields( LLMS_Access_Plan $plan )

Retrieve an array of form fields used for the “free enrollment” form


Description Description

This is the "one-click" enrollment form used when a logged-in user clicks the "checkout" button from an access plan.

This function converts the checkout form to hidden fields, the result is that users with all required fields will be enrolled into the course with a single click (no need to head to the checkout page) and users who are missing required information will be directed to the checkout page.


Top ↑

Parameters Parameters

$plan

(LLMS_Access_Plan) (Required) Access plan being used for enrollment.


Top ↑

Return Return

(array[]) List of LLMS_Form_Field settings arrays.


Top ↑

Source Source

File: includes/forms/class-llms-forms.php

	public function get_free_enroll_form_fields( $plan ) {

		// Convert all fields to hidden fields and remove any fields hidden by LLMS block-level visibility settings.
		add_filter( 'llms_forms_block_to_field_settings', array( $this, 'prepare_field_for_free_enroll_form' ), 999, 3 );
		$fields = $this->get_form_fields( 'checkout', compact( 'plan' ) );
		remove_filter( 'llms_forms_block_to_field_settings', array( $this, 'prepare_field_for_free_enroll_form' ), 999, 3 );

		// If no fields are found, ensure we add to an array instead of casting false to an array (causing a PHP 8.1 deprecation warning).
		$fields = ! is_array( $fields ) ? array() : $fields;

		// Add additional fields required for form processing.
		$fields[] = array(
			'name'           => 'free_checkout_redirect',
			'type'           => 'hidden',
			'value'          => $plan->get_redirection_url( false ),
			'data_store_key' => false,
		);

		$fields[] = array(
			'id'             => 'llms-plan-id',
			'name'           => 'llms_plan_id',
			'type'           => 'hidden',
			'value'          => $plan->get( 'id' ),
			'data_store_key' => false,
		);

		/**
		 * Filter the list of LLMS_Form_Fields used to generate the "free enrollment" form
		 *
		 * @since 5.0.0
		 *
		 * @param array[]          $fields List of LLMS_Form_Field settings arrays.
		 * @param LLMS_Access_Plan $plan   Access plan being used for enrollment.
		 */
		return apply_filters( 'llms_forms_get_free_enroll_form_fields', $fields, $plan );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Retrieve and use the free checkout redirect URL as not encoded.
5.9.0 Fix php 8.1 deprecation warnings when get_form_fields() returns false.
5.1.0 Specifiy to pass the new 3rd param to the llms_forms_block_to_field_settings filter callback.
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.