LLMS_Lab_Pricing_Table_Module

LifterLMS Course/Membership Pricing Table Module HTML class.


Source Source

File: includes/beaver-builder/modules/pricing-table/class.llms.lab.pricing.table.module.php

class LLMS_Lab_Pricing_Table_Module extends FLBUilderModule {

	/**
	 * Constructor.
	 *
	 * @since 1.3.0
	 * @since 1.7.0 Escape strings.
	 *
	 * @return void
	 */
	public function __construct() {
		parent::__construct(
			array(
				'name'          => esc_html__( 'Pricing Table', 'lifterlms' ),
				'description'   => esc_html__( 'LifterLMS Course / Membership Pricing Table', 'lifterlms' ),
				'category'      => esc_html__( 'LifterLMS Modules', 'lifterlms' ),
				'dir'           => LLMS_BB_MODULES_DIR . 'pricing-table/',
				'url'           => LLMS_BB_MODULES_URL . 'pricing-table/',
				'editor_export' => false,
				'enabled'       => true,
			)
		);

		// Ensure pricing tables always display when used within a BB module.
		add_action( 'llms_lab_bb_before_pricing_table', array( $this, 'add_force_show_table_filter' ) );
		add_action( 'lifterlms_after_access_plans', array( $this, 'remove_force_show_table_filter' ) );

		// Ensure pricing tables always display when the frontend builder is active.
		add_filter( 'llms_product_pricing_table_enrollment_status', array( $this, 'show_table' ) );
	}

	/**
	 * Force display of pricing tables within BB modules.
	 *
	 * @since 1.3.0
	 *
	 * @return void
	 */
	public function add_force_show_table_filter() {
		add_filter( 'llms_product_pricing_table_enrollment_status', '__return_false' );
	}

	/**
	 * Remove force display after pricing tables within BB modules.
	 *
	 * @since 1.3.0
	 *
	 * @return void
	 */
	public function remove_force_show_table_filter() {
		remove_filter( 'llms_product_pricing_table_enrollment_status', '__return_false' );
	}

	/**
	 * Get the product ID to be used based of BB module settings.
	 *
	 * @since 1.3.0
	 * @since 1.3.0 Use strict comparison for `in_array`.
	 *
	 * @param obj $settings BB node settings object.
	 * @return int|false
	 */
	public function get_product_id( $settings ) {

		$type = $settings->llms_product_type;
		if ( ! $type ) {
			$id = get_the_ID();
		} elseif ( 'course' === $type || 'membership' === $type ) {
			$key = sprintf( 'llms_%s_id', $type );
			$id  = $settings->$key;
		}

		if ( in_array( get_post_type( $id ), array( 'lesson', 'llms_quiz' ), true ) ) {
			$course = llms_get_post_parent_course( $id );
			$id     = $course->get( 'id' );
		}

		// If the current id isn't a course or membership don't proceed.
		if ( ! in_array( get_post_type( $id ), array( 'course', 'llms_membership' ), true ) ) {
			return false;
		}

		return $id;
	}

	/**
	 * Always show the pricing table when the builder is active.
	 *
	 * @since 1.3.0
	 *
	 * @param bool $enrollment Enrollment status of the current user.
	 * @return bool
	 */
	public function show_table( $enrollment ) {

		if ( FLBuilderModel::is_builder_active() ) {
			return false;
		}

		return $enrollment;
	}
}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
1.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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