LLMS_Access_Plan::get_price_with_coupon( string $key, LLMS_Coupon|int $coupon_id, array $price_args = array(), string $format = 'html' )
Apply a coupon to a price
Parameters Parameters
- $key
-
(string) (Required) Price to retrieve, "price", "sale_price", or "trial_price".
- $coupon_id
-
(LLMS_Coupon|int) (Required) Coupon object or post id.
- $price_args
-
(array) (Optional) arguments to be passed to
llms_price()
.Default value: array()
- $format
-
(string) (Optional) return format as passed to
llms_price()
.Default value: 'html'
Return Return
(mixed)
Source Source
File: includes/models/model.llms.access.plan.php
// Allow id or instance to be passed for $coupon_id. if ( $coupon_id instanceof LLMS_Coupon ) { $coupon = $coupon_id; } else { $coupon = new LLMS_Coupon( $coupon_id ); } $price = $this->get( $key ); // Ensure the coupon *can* be applied to this plan. if ( ! $coupon->is_valid( $this ) ) { return $price; } $discount_type = $coupon->get( 'discount_type' ); // Price and sale price are calculated of coupon amount. if ( 'price' === $key || 'sale_price' === $key ) { $coupon_amount = $coupon->get( 'coupon_amount' ); } elseif ( 'trial_price' === $key && $coupon->has_trial_discount() && $this->has_trial() ) { $coupon_amount = $coupon->get( 'trial_amount' ); } else { $coupon_amount = 0; } if ( $coupon_amount ) { // Simple subtraction. if ( 'dollar' === $discount_type ) { $price = $price - $coupon_amount; } elseif ( 'percent' === $discount_type ) { $price = $price - ( $price * ( $coupon_amount / 100 ) ); } } // If price is less than 0 return the pricing text. if ( $price <= 0 ) { $price = $this->get_free_pricing_text( $format ); } else { if ( 'html' === $format || 'raw' === $format ) { $price = llms_price( $price, $price_args ); if ( 'raw' === $format ) { $price = wp_strip_all_tags( $price ); } } elseif ( 'float' === $format ) { $price = floatval( number_format( $price, get_lifterlms_decimals(), '.', '' ) ); } else { $price = apply_filters( "llms_get_{$this->model_post_type}_{$key}_{$format}_with_coupon", $price, $key, $price_args, $format, $this ); } } return apply_filters( "llms_get_{$this->model_post_type}_{$key}_price_with_coupon", $price, $key, $price_args, $format, $this ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.7.0 | Unknown. |
3.40.0 | Use wp_strip_all_tags() in favor of strip_tags() . |
3.0.0 | Introduced. |