invp_get_the_price( string $zero_string = null, int|null $post_ID = null )
Template tag. Returns the vehicle’s price.
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
Return Return
(string) 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.
Source Source
File: includes/template-tags.php
function invp_get_the_price( $zero_string = null, $post_ID = null ) {
if ( empty( $post_ID ) ) {
$post_ID = get_the_ID();
}
// If this vehicle is sold, just say so.
if ( invp_is_sold( $post_ID ) ) {
$sold_text = apply_filters( 'invp_sold_text', esc_html__( 'SOLD!', 'inventory-presser' ) );
return wp_kses_post( apply_filters( 'invp_sold_string', sprintf( '<span class="vehicle-sold">%s</span>', esc_html( $sold_text ) ) ) );
}
// If the vehicle is pending, just say so.
if ( invp_is_pending( $post_ID ) ) {
return wp_kses_post( apply_filters( 'invp_pending_string', sprintf( '<span class="vehicle-pending">%s</span>', esc_html__( 'Sale Pending', '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 wp_kses_post( apply_filters( 'invp_price_display', esc_html( 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 .= INVP::currency_symbol() . number_format( $price, 0, '.', ',' );
}
$down_payment = invp_get_the_down_payment( $post_ID );
if ( ! empty( $down_payment ) ) {
if ( ! empty( $output ) ) {
$output .= esc_html( apply_filters( 'invp_price_display_separator', ' / ', $settings['price_display'], $post_ID ) );
}
$output .= sprintf( '%s Down', esc_html( $down_payment ) );
}
if ( '' === $output ) {
return wp_kses_post( apply_filters( 'invp_price_display', esc_html( $zero_string ), $settings['price_display'], $post_ID ) );
}
return wp_kses_post( apply_filters( 'invp_price_display', esc_html( $output ), $settings['price_display'], $post_ID ) );
// down payment only.
case 'down_only':
$down_payment = invp_get_the_down_payment( $post_ID );
if ( ! empty( $down_payment ) ) {
return wp_kses_post( apply_filters( 'invp_price_display', sprintf( '%s %s', esc_html( $down_payment ), esc_html__( 'Down', 'inventory-presser' ) ), $settings['price_display'], $post_ID ) );
}
return wp_kses_post( apply_filters( 'invp_price_display', esc_html( $zero_string ), $settings['price_display'], $post_ID ) );
// call_for_price.
case 'call_for_price':
// Not $zero_string, but explicity "Call for Price".
return wp_kses_post( apply_filters( 'invp_price_display', esc_html__( '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 wp_kses_post( 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>',
esc_html( apply_filters( 'invp_price_was_now_discount_retail', __( 'Retail', 'inventory-presser' ) ) ),
esc_html( invp_get_the_msrp( $post_ID ) ),
esc_html( apply_filters( 'invp_price_was_now_discount_now', __( 'Now', 'inventory-presser' ) ) ),
esc_html( number_format( $price, 0, '.', ',' ) ),
esc_html( apply_filters( 'invp_price_was_now_discount_save', __( 'You Save', 'inventory-presser' ) ) ),
esc_html( 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 wp_kses_post( apply_filters( 'invp_price_display', esc_html( INVP::currency_symbol() . 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 wp_kses_post( apply_filters( 'invp_price_display', esc_html( $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 wp_kses_post( apply_filters(
'invp_price_display',
sprintf(
'%s %s',
esc_html( $payment ),
esc_html( $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 wp_kses_post( apply_filters( 'invp_price_display', esc_html( $zero_string ), $settings['price_display'], $post_ID ) );
}
return wp_kses_post( apply_filters( 'invp_price_display', esc_html( INVP::currency_symbol() . number_format( $price, 0, '.', ',' ) ), $settings['price_display'], $post_ID ) );
case 'down_and_payment':
$string = '';
$down_payment = invp_get_the_down_payment( $post_ID );
$payment = invp_get_the_payment( $post_ID );
if ( ! empty( $down_payment ) ) {
$string .= sprintf(
'%s %s',
esc_html( $down_payment ),
esc_html__( 'Down', 'inventory-presser' )
);
}
if ( ! empty( $payment ) ) {
if ( ! empty( $string ) ) {
$string .= esc_html( apply_filters( 'invp_price_display_separator', ' / ', $settings['price_display'], $post_ID ) );
}
$string .= sprintf(
'%s %s',
esc_html( $payment ),
esc_html( ucfirst( invp_get_the_payment_frequency( $post_ID ) ) )
);
}
return wp_kses_post( apply_filters( 'invp_price_display', esc_html( $string ), $settings['price_display'], $post_ID ) );
default:
/**
* The price display type is something beyond what this
* plugin supports. Allow the value to be filtered.
*/
return wp_kses_post( apply_filters( 'invp_price_display', esc_html( $zero_string ), $settings['price_display'], $post_ID ) );
}
return $zero_string;
}
Expand full source codeCollapse full source codeView on Github