invp_get_the_price( string $zero_string = null, int|null $post_ID = null )

invp_get_the_price


Description Description

Template tag. Returns the vehicle's price.

Returns the price as a dollar amount with a dollar sign except when it is zero or the vehicle is sold. Returns the $zero_string when the price is zero. Returns "SOLD!" when the vehicle is sold.


Top ↑

Parameters Parameters

$zero_string

(string) (Optional) The text to display when the price is zero

Default value: null

$post_ID

(int|null) (Optional) The post ID of a vehicle. Must be passed when using this method outside the loop.

Default value: null


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/template-tags.php

		$post_ID = get_the_ID();
	}

	// If this vehicle is sold, just say so.
	if ( invp_is_sold( $post_ID ) ) {
		return apply_filters( 'invp_sold_string', sprintf( '<span class="vehicle-sold">%s</span>', __( 'SOLD!', 'inventory-presser' ) ) );
	}

	if ( null === $zero_string ) {
		$zero_string = __( 'Call For Price', 'inventory-presser' );
	}
	$zero_string = apply_filters( 'invp_zero_price_string', $zero_string, $post_ID );

	// How are we displaying the price?
	$settings = INVP::settings();
	if ( ! isset( $settings['price_display'] ) ) {
		$settings['price_display'] = 'default';
	}

	switch ( $settings['price_display'] ) {
		case 'msrp':
			return apply_filters( 'invp_price_display', invp_get_the_msrp( $post_ID ), $settings['price_display'], $post_ID );

		// ${Price} / ${Down Payment} Down.
		case 'full_or_down':
			$output = '';
			$price  = invp_get_raw_price( $post_ID );
			if ( ! empty( $price ) ) {
				$output .= sprintf( '$%s', number_format( $price, 0, '.', ',' ) );
			}

			$down_payment = invp_get_the_down_payment();
			if ( ! empty( $down_payment ) ) {
				$output .= sprintf( ' / %s Down', $down_payment );
			}

			if ( '' === $output ) {
				return apply_filters( 'invp_price_display', $zero_string, $settings['price_display'], $post_ID );
			}
			return apply_filters( 'invp_price_display', $output, $settings['price_display'], $post_ID );

		// down payment only.
		case 'down_only':
			$down_payment = invp_get_the_down_payment();
			if ( ! empty( $down_payment ) ) {
				return apply_filters( 'invp_price_display', sprintf( '%s %s', $down_payment, __( 'Down', 'inventory-presser' ) ), $settings['price_display'], $post_ID );
			}
			return apply_filters( 'invp_price_display', $zero_string, $settings['price_display'], $post_ID );

		// call_for_price.
		case 'call_for_price':
			// Not $zero_string, but explicity "Call for Price".
			return apply_filters( 'invp_price_display', __( 'Call For Price', 'inventory-presser' ), $settings['price_display'], $post_ID );

		// was_now_discount - MSRP = was price, regular price = now price, discount = was - now.
		case 'was_now_discount':
			$msrp  = INVP::get_meta( 'msrp', $post_ID ); // raw!
			$price = invp_get_raw_price( $post_ID );
			if ( ! empty( $msrp )
				&& ! empty( $price )
				&& $msrp > $price ) {

				return apply_filters(
					'invp_price_display',
					sprintf(
						'<div class="price-was-discount">%s %s</div>%s $%s<div class="price-was-discount-save">%s $%s</div>',
						apply_filters( 'invp_price_was_now_discount_retail', __( 'Retail', 'inventory-presser' ) ),
						invp_get_the_msrp( $post_ID ),
						apply_filters( 'invp_price_was_now_discount_now', __( 'Now', 'inventory-presser' ) ),
						number_format( $price, 0, '.', ',' ),
						apply_filters( 'invp_price_was_now_discount_save', __( 'You Save', 'inventory-presser' ) ),
						number_format( ( $msrp - $price ), 0, '.', ',' )
					),
					$settings['price_display'],
					$post_ID
				);
			}

			// Either no discount between the two prices or one is empty.
			if ( ! empty( $price ) ) {
				// We have a price, so fallback to "default" behavior and show it.
				return apply_filters( 'invp_price_display', '$' . number_format( $price, 0, '.', ',' ), $settings['price_display'], $post_ID );
			}
			break;

		// $75 per week.
		case 'payment_only':
			$payment           = invp_get_the_payment( $post_ID );
			$payment_frequency = invp_get_the_payment_frequency( $post_ID );
			if ( empty( $payment ) || empty( $payment_frequency ) ) {
				return apply_filters( 'invp_price_display', $zero_string, $settings['price_display'], $post_ID );
			}

			switch ( $payment_frequency ) {
				case 'weekly':
					$payment_frequency = __( 'per week', 'inventory-presser' );
					break;

				case 'monthly':
					$payment_frequency = __( 'per month', 'inventory-presser' );
					break;

				case 'biweekly':
					$payment_frequency = __( 'every other week', 'inventory-presser' );
					break;

				case 'semimonthly':
					$payment_frequency = __( 'twice a month', 'inventory-presser' );
					break;
			}
			return apply_filters(
				'invp_price_display',
				sprintf(
					'%s %s',
					$payment,
					$payment_frequency
				),
				$settings['price_display'],
				$post_ID
			);

		case 'default':
			// Normally, show the price field as currency.
			$price = invp_get_raw_price( $post_ID );
			if ( empty( $price ) ) {
				return apply_filters( 'invp_price_display', $zero_string, $settings['price_display'], $post_ID );
			}
			return apply_filters( 'invp_price_display', '$' . number_format( $price, 0, '.', ',' ), $settings['price_display'], $post_ID );

		case 'down_and_payment':
			$string       = '';
			$down_payment = invp_get_the_down_payment();
			$payment      = invp_get_the_payment( $post_ID );
			if ( ! empty( $down_payment ) ) {
				$string .= sprintf(
					'%s %s',
					$down_payment,
					__( 'Down', 'inventory-presser' ),
				);
			}
			if ( ! empty( $payment ) ) {
				if ( ! empty( $string ) ) {
					$string .= ' / ';
				}
				$string .= sprintf(
					'%s %s',