LLMS_Post_Model::get_price( string $key, array $price_args = array(), string $format = 'html' )

Getter for price strings with optional formatting options


Parameters Parameters

$key

(string) (Required) Property key.

$price_args

(array) (Optional) Array of arguments that can be passed to llms_price(). Default is empty array.

Default value: array()

$format

(string) (Optional) Format conversion method [html|raw|float]. Default is 'html'.

Default value: 'html'


Top ↑

Return Return

(mixed)


Top ↑

Source Source

File: includes/abstracts/abstract.llms.post.model.php

	public function get_price( $key, $price_args = array(), $format = 'html' ) {

		$price = $this->get( $key );

		// Handle empty or unset values gracefully.
		if ( '' === $price ) {
			$price = 0;
		}

		if ( 'html' === $format || 'raw' === $format ) {
			$price = llms_price( $price, $price_args );
			if ( 'raw' === $format ) {
				$price = strip_tags( $price );
			}
		} elseif ( 'float' === $format ) {
			$price = floatval( number_format( $price, get_lifterlms_decimals(), '.', '' ) );
		} else {
			/**
			* Allows applying custom formatting to price(s).
			*
			* This is only fired when the `get_price()`'s `$format` passed param is not one of html|raw|float.
			*
			* @since Unknown
			*
			* The first dynamic portion of this hook, `$this->model_post_type`, refers to the model's post type. For example "course",
			* "lesson", "membership", etc...
			* The second dynamic part of this hook, `$key`, refers to the price property name.
			* The third dynamic part of this hook, `$format`, refers to the custom format conversion method.
			*/
			$price = apply_filters( "llms_get_{$this->model_post_type}_{$key}_{$format}", $price, $key, $price_args, $format, $this );
		}

		/**
		 * Filters the price(s)
		 *
		 * The first dynamic portion of this hook, `$this->model_post_type`, refers to the model's post type. For example "course",
		 * "lesson", "membership", etc...
		 * The second dynamic part of this hook, `$key`, refers to the price property name.
		 *
		 * @since Unknown
		 *
		 * @param string          $price      The maybe formatted price.
		 * @param string          $key        The price property name.
		 * @param array           $price_args Array of arguments that can be passed to llms_price().
		 * @param string          $format     Format conversion method.
		 * @param LLMS_Post_Model $llms_post The LLMS_Post_Model instance.
		 */
		return apply_filters( "llms_get_{$this->model_post_type}_{$key}_price", $price, $key, $price_args, $format, $this );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.8.0 Use strict type comparison where possible.
3.7.0 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.