LLMS_Product::get_access_plans( bool $free_only = false, bool $visible_only = true )

Get all access plans for the product.


Parameters Parameters

$free_only

(bool) (Optional) Only include free access plans if true. Defalt false

Default value: false

$visible_only

(bool) (Optional) Excludes hidden access plans from results. Default true.

Default value: true


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/models/model.llms.product.php

	public function get_access_plans( $free_only = false, $visible_only = true ) {

		$args = array(
			'meta_key'       => '_llms_product_id', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
			'meta_value'     => $this->get( 'id' ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
			'order'          => 'ASC',
			'orderby'        => 'menu_order',
			'posts_per_page' => $this->get_access_plan_limit(),
			'post_type'      => 'llms_access_plan',
			'post_status'    => 'publish',
		);

		// Filter results to only free access plans.
		if ( $free_only ) {
			$args['meta_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
				array(
					'key'   => '_llms_is_free',
					'value' => 'yes',
				),
			);
		}

		// Exclude hidden access plans from the results.
		if ( $visible_only ) {
			$args['tax_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
				array(
					'field'    => 'name',
					'operator' => 'NOT IN',
					'terms'    => array( 'hidden' ),
					'taxonomy' => 'llms_access_plan_visibility',
				),
			);
		}

		/**
		 * Filter the product's access plan query args.
		 *
		 * @since Unknown
		 *
		 * @param array        $args         Query args.
		 * @param LLMS_Product $product      The LLMS_Product instance.
		 * @param bool         $free_only    Whether or not to include the free access plans only.
		 * @param bool         $visbile_only Whether or not to exclude the hidden access plans.
		 */
		$query = new WP_Query( apply_filters( 'llms_get_product_access_plans_args', $args, $this, $free_only, $visible_only ) );

		$plans = array();

		// If we have plans, setup access plan instances.
		if ( $query->have_posts() ) {
			foreach ( $query->posts as $post ) {
				$plans[] = new LLMS_Access_Plan( $post );
			}
		}

		/**
		 * Filter the product's access plans.
		 *
		 * @since Unknown
		 *
		 * @param array        $plans        An array of LLMS_Access_Plan instances related to the product `$product`.
		 * @param LLMS_Product $product      The LLMS_Product instance.
		 * @param bool         $free_only    Whether or not to include the free access plans only.
		 * @param bool         $visbile_only Whether or not to exclude the hidden access plans.
		 */
		return apply_filters( 'llms_get_product_access_plans', $plans, $this, $free_only, $visible_only );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.37.17 Fixed a typo in the post_status query arg when retrieving access plans for this product.
3.25.2 Unknown.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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