/** * Creates a subscription price string from an array of subscription details. For example, ""$5 / month for 12 months". * * @param array $subscription_details A set of name => value pairs for the subscription details to include in the string. Available keys: * 'initial_amount': The upfront payment for the subscription, including sign up fees, as a string from the @see woocommerce_price(). Default empty string (no initial payment) * 'initial_description': The word after the initial payment amount to describe the amount. Examples include "now" or "initial payment". Defaults to "up front". * 'recurring_amount': The amount charged per period. Default 0 (no recurring payment). * 'subscription_interval': How regularly the subscription payments are charged. Default 1, meaning each period e.g. per month. * 'subscription_period': The temporal period of the subscription. Should be one of {day|week|month|year} as used by @see self::get_subscription_period_strings() * 'subscription_length': The total number of periods the subscription should continue for. Default 0, meaning continue indefinitely. * 'trial_length': The total number of periods the subscription trial period should continue for. Default 0, meaning no trial period. * 'trial_period': The temporal period for the subscription's trial period. Should be one of {day|week|month|year} as used by @see self::get_subscription_period_strings() * @since 1.2 * @deprecated 2.0 * @return float $proportion A proportion of the total (e.g. 0.5 is half of the total) */ public static function get_subscription_price_string($subscription_details) { _deprecated_function(__METHOD__, '2.0', 'wcs_price_string()'); return wcs_price_string($subscription_details); }
/** * Creates a string representation of the subscription period/term for each item in the cart * * @param string $initial_amount The initial amount to be displayed for the subscription as passed through the @see woocommerce_price() function. * @param float $recurring_amount The price to display in the subscription. * @param array $args (optional) Flags to customise to display the trial and length of the subscription. Default to false - don't display. * @since 1.0 * @deprecated 2.0 */ public static function get_cart_subscription_string($initial_amount, $recurring_amount, $args = array()) { _deprecated_function(__METHOD__, '2.0', 'values from WC()->cart->recurring_carts'); if (!is_array($args)) { _deprecated_argument(__CLASS__ . '::' . __FUNCTION__, '1.4', 'Third parameter is now an array of name => value pairs. Use array( "include_lengths" => true ) instead.'); $args = array('include_lengths' => $args); } $args = wp_parse_args($args, array('include_lengths' => false, 'include_trial' => true)); $subscription_details = array('initial_amount' => $initial_amount, 'initial_description' => __('now', 'woocommerce-subscriptions'), 'recurring_amount' => $recurring_amount, 'subscription_interval' => self::get_cart_subscription_interval(), 'subscription_period' => self::get_cart_subscription_period(), 'trial_length' => self::get_cart_subscription_trial_length(), 'trial_period' => self::get_cart_subscription_trial_period()); $is_one_payment = self::get_cart_subscription_length() > 0 && self::get_cart_subscription_length() == self::get_cart_subscription_interval() ? true : false; // Override defaults when subscription is for one billing period if ($is_one_payment) { $subscription_details['subscription_length'] = self::get_cart_subscription_length(); } else { if (true === $args['include_lengths']) { $subscription_details['subscription_length'] = self::get_cart_subscription_length(); } if (false === $args['include_trial']) { $subscription_details['trial_length'] = 0; } } $initial_amount_string = is_numeric($subscription_details['initial_amount']) ? woocommerce_price($subscription_details['initial_amount']) : $subscription_details['initial_amount']; $recurring_amount_string = is_numeric($subscription_details['recurring_amount']) ? woocommerce_price($subscription_details['recurring_amount']) : $subscription_details['recurring_amount']; // Don't show up front fees when there is no trial period and no sign up fee and they are the same as the recurring amount if (self::get_cart_subscription_trial_length() == 0 && self::get_cart_subscription_sign_up_fee() == 0 && $initial_amount_string == $recurring_amount_string) { $subscription_details['initial_amount'] = ''; } elseif (wc_price(0) == $initial_amount_string && false === $is_one_payment && self::get_cart_subscription_trial_length() > 0) { // don't show $0.00 initial amount (i.e. a free trial with no non-subscription products in the cart) unless the recurring period is the same as the billing period $subscription_details['initial_amount'] = ''; } // Include details of a synced subscription in the cart if ($synchronised_cart_item = WC_Subscriptions_Synchroniser::cart_contains_synced_subscription()) { $subscription_details += array('is_synced' => true, 'synchronised_payment_day' => WC_Subscriptions_Synchroniser::get_products_payment_day($synchronised_cart_item['data'])); } $subscription_details = apply_filters('woocommerce_cart_subscription_string_details', $subscription_details, $args); $subscription_string = wcs_price_string($subscription_details); return $subscription_string; }
/** * Return a formatted price string for a given cart object * * @access public * @return void */ function wcs_cart_price_string($recurring_amount, $cart) { return wcs_price_string(apply_filters('woocommerce_cart_subscription_string_details', array('recurring_amount' => $recurring_amount, 'subscription_interval' => wcs_cart_pluck($cart, 'subscription_period_interval'), 'subscription_period' => wcs_cart_pluck($cart, 'subscription_period', ''), 'subscription_length' => wcs_cart_pluck($cart, 'subscription_length')))); }
/** * Gets order total - formatted for display. * * @return string */ public function get_formatted_order_total($tax_display = '', $display_refunded = true) { if ($this->get_total() > 0 && !empty($this->billing_period)) { $formatted_order_total = wcs_price_string($this->get_price_string_details($this->get_total())); } else { $formatted_order_total = parent::get_formatted_order_total(); } return apply_filters('woocommerce_get_formatted_subscription_total', $formatted_order_total, $this); }