本文整理汇总了PHP中WC_Subscriptions_Manager::get_subscription_price_string方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::get_subscription_price_string方法的具体用法?PHP WC_Subscriptions_Manager::get_subscription_price_string怎么用?PHP WC_Subscriptions_Manager::get_subscription_price_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Manager
的用法示例。
在下文中一共展示了WC_Subscriptions_Manager::get_subscription_price_string方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_cart_subscription_string
/**
* 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
*/
public static function get_cart_subscription_string($initial_amount, $recurring_amount, $args = array())
{
global $woocommerce;
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.', 'woocommerce-subscriptions'));
$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());
if (true === $args['include_lengths']) {
$subscription_details += array('subscription_length' => self::get_cart_subscription_length());
}
if (false === $args['include_trial']) {
$subscription_details['trial_length'] = 0;
}
// Override defaults when subscription is for one billing period
if (self::get_cart_subscription_length() > 0 && self::get_cart_subscription_length() == self::get_cart_subscription_interval()) {
$subscription_details += array('subscription_length' => self::get_cart_subscription_length());
}
$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 (self::get_cart_subscription_trial_length() > 0 && self::get_cart_subscription_sign_up_fee() == 0) {
/* The order total of a subscription with a free trial is equal to the recurring amount (instead of 0), because an order won't be paid for if it has a total of 0, a patch to allow payment on orders with 0 is coming in WC 1.7 */
$subscription_details['initial_amount'] = '';
}
$subscription_details = apply_filters('woocommerce_cart_subscription_string_details', $subscription_details, $args);
$subscription_string = WC_Subscriptions_Manager::get_subscription_price_string($subscription_details);
return $subscription_string;
}
示例2: get_order_item_totals
/**
* Individual totals are taken care of by filters, but taxes and fees are not, so we need to override them here.
*
* @since 1.0
*/
public static function get_order_item_totals($total_rows, $order)
{
global $woocommerce;
if (self::order_contains_subscription($order) && self::get_recurring_total_tax($order) > 0 && 'incl' !== $order->tax_display_cart) {
$order_taxes = $order->get_taxes();
$recurring_taxes = self::get_recurring_taxes($order);
$subscription_length = self::get_subscription_length($order);
$sign_up_fee = self::get_sign_up_fee($order);
$trial_length = self::get_subscription_trial_length($order);
// Only want to display recurring amounts for taxes, no need for trial period, length etc.
$subscription_details = array('currency' => self::get_order_currency($order), 'subscription_interval' => self::get_subscription_interval($order), 'subscription_period' => self::get_subscription_period($order));
if (count($order_taxes) > 0 || count($recurring_taxes) > 0) {
if ('itemized' == get_option('woocommerce_tax_total_display')) {
foreach ($recurring_taxes as $index => $tax) {
if ($tax['compound']) {
continue;
}
$tax_key = sanitize_title($tax['name']);
$tax_name = $tax['name'];
$tax_amount = $tax['tax_amount'];
$shipping_tax = $tax['shipping_tax_amount'];
if ($tax['tax_amount'] > 0) {
foreach ($order_taxes as $order_tax) {
if ($tax_name == $order_tax['name']) {
$order_tax_amount = isset($order_tax['tax_amount']) ? $order_tax['tax_amount'] + $order_tax['shipping_tax_amount'] : '';
}
}
$recurring_tax = isset($tax['tax_amount']) ? $tax['tax_amount'] + $tax['shipping_tax_amount'] : '';
}
if ($tax_amount > 0) {
$subscription_details['recurring_amount'] = $recurring_tax;
if (self::$recurring_only_price_strings) {
$subscription_details['initial_amount'] = '';
} elseif ($sign_up_fee > 0 && $trial_length == 0 && $subscription_details['subscription_interval'] != $subscription_length) {
$subscription_details['initial_amount'] = $total_rows[$tax_key]['value'];
} elseif ($sign_up_fee > 0 && $trial_length > 0) {
$subscription_details['initial_amount'] = $total_rows[$tax_key]['value'];
} elseif ($order_tax_amount !== $subscription_details['recurring_amount']) {
// Applying initial payment only discount
$subscription_details['initial_amount'] = $total_rows[$tax_key]['value'];
} else {
$subscription_details['initial_amount'] = '';
}
$total_rows[$tax_key]['value'] = WC_Subscriptions_Manager::get_subscription_price_string($subscription_details);
} elseif ($shipping_tax > 0) {
// Just a recurring shipping tax
$subscription_details['recurring_amount'] = $shipping_tax;
if (self::$recurring_only_price_strings) {
$subscription_details['initial_amount'] = '';
} elseif ($sign_up_fee > 0 && $trial_length == 0 && $subscription_details['subscription_interval'] != $subscription_length) {
$subscription_details['initial_amount'] = $shipping_tax;
} elseif ($sign_up_fee > 0 && $trial_length > 0) {
$subscription_details['initial_amount'] = $shipping_tax;
} elseif ($shipping_tax !== $subscription_details['recurring_amount']) {
// Applying initial payment only discount
$subscription_details['initial_amount'] = $shipping_tax;
} else {
$subscription_details['initial_amount'] = '';
}
$shipping_tax_row = array($tax_key . '_shipping' => array('label' => $tax_name, 'value' => WC_Subscriptions_Manager::get_subscription_price_string($subscription_details)));
// Insert the tax just before the order total
$total_rows = array_splice($total_rows, 0, -1) + $shipping_tax_row + array_splice($total_rows, -1);
}
}
foreach ($recurring_taxes as $index => $tax) {
if (!$tax['compound']) {
continue;
}
$tax_key = sanitize_title($tax['label']);
$tax_name = $tax['label'];
$tax_amount = $tax['cart_tax'];
$shipping_tax = $tax['shipping_tax'];
if ($tax_amount > 0) {
foreach ($order_taxes as $order_tax) {
if ($tax_name == $order_tax['label']) {
$order_tax_amount = isset($order_tax['cart_tax']) ? $order_tax['cart_tax'] + $order_tax['shipping_tax'] : '';
}
}
$recurring_tax = isset($tax['cart_tax']) ? $tax['cart_tax'] + $tax['shipping_tax'] : '';
}
if ($tax_amount > 0) {
if (self::$recurring_only_price_strings) {
$subscription_details['initial_amount'] = '';
} elseif ($sign_up_fee > 0 && $trial_length == 0 && $subscription_details['subscription_interval'] != $subscription_length) {
$subscription_details['initial_amount'] = $total_rows[$tax_key]['value'];
} elseif ($sign_up_fee > 0 && $trial_length > 0) {
$subscription_details['initial_amount'] = $total_rows[$tax_key]['value'];
} elseif ($order_tax_amount !== woocommerce_price($subscription_details['recurring_amount'])) {
// Applying initial payment only discount
$subscription_details['initial_amount'] = $total_rows[$tax_key]['value'];
} else {
$subscription_details['initial_amount'] = '';
}
$subscription_details['recurring_amount'] = $recurring_tax;
$total_rows[$tax_key]['value'] = WC_Subscriptions_Manager::get_subscription_price_string($subscription_details);
//.........这里部分代码省略.........
示例3: get_cart_subscription_string
/**
* 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
*/
public static function get_cart_subscription_string($initial_amount, $recurring_amount, $args = array())
{
global $woocommerce;
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.', 'woocommerce-subscriptions'));
$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 = WC_Subscriptions_Manager::get_subscription_price_string($subscription_details);
return $subscription_string;
}
示例4: get_cart_subscription_string
/**
* Creates a string representation of the subscription period/term for each item in the cart
*
* @param $initial_amount string The initial amount to be displayed for the subscription as passed through the @see woocommerce_price() function.
* @param $recurring_amount float The price to display in the subscription.
* @param $include_lengths bool (optional) Whether to display the trial and length of the subscription. Default to false - don't display.
* @since 1.0
*/
public static function get_cart_subscription_string($initial_amount, $recurring_amount, $include_lengths = false)
{
global $woocommerce;
$subscription_details = array('initial_amount' => $initial_amount, 'initial_description' => __('now', WC_Subscriptions::$text_domain), '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());
if ($include_lengths === true) {
$subscription_details += array('subscription_length' => self::get_cart_subscription_length());
}
// Override defaults when subscription is for one billing period
if (self::get_cart_subscription_length() > 0 && self::get_cart_subscription_length() == self::get_cart_subscription_interval()) {
$subscription_details += array('subscription_length' => self::get_cart_subscription_length());
}
// Don't show up front fees when there is no trial period and no sign up fee
if (self::get_cart_subscription_trial_length() == 0 && self::get_cart_subscription_sign_up_fee() == 0) {
$subscription_details['initial_amount'] = '';
} elseif (self::get_cart_subscription_trial_length() > 0 && self::get_cart_subscription_sign_up_fee() == 0) {
/* The order total of a subscription with a free trial is equal to the recurring amount (instead of 0), because an order won't be paid for if it has a total of 0, a patch to allow payment on orders with 0 is coming in WC 1.7 */
$subscription_details['initial_amount'] = '';
}
$subscription_string = WC_Subscriptions_Manager::get_subscription_price_string($subscription_details);
return $subscription_string;
}
示例5: get_order_subscription_string
/**
* Creates a string representation of the subscription period/term for each item in the cart
*
* @param $order WC_Order A WC_Order object.
* @param mixed $deprecated Never used.
* @param mixed $deprecated Never used.
* @since 1.0
*/
public static function get_order_subscription_string($order, $deprecated_price = '', $deprecated_sign_up_fee = '')
{
if (!empty($deprecated_price) || !empty($deprecated_sign_up_fee)) {
_deprecated_argument(__CLASS__ . '::' . __FUNCTION__, '1.2');
}
$subscription_details = array('initial_amount' => self::get_total_initial_payment($order), 'initial_description' => __('now', WC_Subscriptions::$text_domain), 'recurring_amount' => self::get_recurring_total($order), 'subscription_interval' => self::get_subscription_interval($order), 'subscription_period' => self::get_subscription_period($order), 'subscription_length' => self::get_subscription_length($order), 'trial_length' => self::get_subscription_trial_length($order), 'trial_period' => self::get_subscription_trial_period($order));
$subscription_string = WC_Subscriptions_Manager::get_subscription_price_string($subscription_details);
return $subscription_string;
}
示例6: get_order_item_totals
/**
* Individual totals are taken care of by filters, but taxes are not, so we need to override them here.
*
* @since 1.0
*/
public static function get_order_item_totals($total_rows, $order)
{
global $woocommerce;
if (self::order_contains_subscription($order) && self::get_recurring_total_tax($order) > 0 && 'incl' !== $order->tax_display_cart) {
$order_taxes = $order->get_taxes();
$recurring_taxes = self::get_recurring_taxes($order);
$subscription_length = self::get_subscription_length($order);
$sign_up_fee = self::get_sign_up_fee($order);
$trial_length = self::get_subscription_trial_length($order);
// Only want to display recurring amounts for taxes, no need for trial period, length etc.
$subscription_details = array('subscription_interval' => self::get_subscription_interval($order), 'subscription_period' => self::get_subscription_period($order));
if (count($order_taxes) > 0 || count($recurring_taxes) > 0) {
foreach ($recurring_taxes as $index => $tax) {
if ($tax['compound']) {
continue;
}
if (isset($tax['name'])) {
// WC 2.0+
$tax_key = sanitize_title($tax['name']);
$tax_name = $tax['name'];
$tax_amount = $tax['tax_amount'];
$shipping_tax = $tax['shipping_tax_amount'];
if ($tax['tax_amount'] > 0) {
foreach ($order_taxes as $order_tax) {
if ($tax_name == $order_tax['name']) {
$order_tax_amount = isset($order_tax['tax_amount']) ? $order_tax['tax_amount'] + $order_tax['shipping_tax_amount'] : '';
}
}
$recurring_tax = isset($tax['tax_amount']) ? $tax['tax_amount'] + $tax['shipping_tax_amount'] : '';
}
} else {
// WC 1.x structure
$tax_key = sanitize_title($tax['label']);
$tax_name = $tax['label'];
$tax_amount = $tax['cart_tax'];
$shipping_tax = $tax['shipping_tax'];
if ($tax_amount > 0) {
foreach ($order_taxes as $order_tax) {
if ($tax_name == $order_tax['label']) {
$order_tax_amount = isset($order_tax['cart_tax']) ? $order_tax['cart_tax'] + $order_tax['shipping_tax'] : '';
}
}
$recurring_tax = isset($recurring_taxes[$index]['cart_tax']) ? $recurring_taxes[$index]['cart_tax'] + $recurring_taxes[$index]['shipping_tax'] : '';
}
}
if ($tax_amount > 0) {
$subscription_details['recurring_amount'] = $recurring_tax;
if ($sign_up_fee > 0 && $trial_length == 0 && $subscription_details['subscription_interval'] != $subscription_length) {
$subscription_details['initial_amount'] = $order_tax_amount;
} elseif ($sign_up_fee > 0 && $trial_length > 0) {
$subscription_details['initial_amount'] = $order_tax_amount;
} elseif ($order_tax_amount !== $subscription_details['recurring_amount']) {
// Applying initial payment only discount
$subscription_details['initial_amount'] = $order_tax_amount;
} else {
$subscription_details['initial_amount'] = '';
}
$total_rows[$tax_key]['value'] = WC_Subscriptions_Manager::get_subscription_price_string($subscription_details);
} elseif ($shipping_tax > 0) {
// Just a recurring shipping tax
$subscription_details['recurring_amount'] = $shipping_tax;
if ($sign_up_fee > 0 && $trial_length == 0 && $subscription_details['subscription_interval'] != $subscription_length) {
$subscription_details['initial_amount'] = $shipping_tax;
} elseif ($sign_up_fee > 0 && $trial_length > 0) {
$subscription_details['initial_amount'] = $shipping_tax;
} elseif ($shipping_tax !== $subscription_details['recurring_amount']) {
// Applying initial payment only discount
$subscription_details['initial_amount'] = $shipping_tax;
} else {
$subscription_details['initial_amount'] = '';
}
$shipping_tax_row = array($tax_key . '_shipping' => array('label' => $tax_name, 'value' => WC_Subscriptions_Manager::get_subscription_price_string($subscription_details)));
// Insert the tax just before the order total
$total_rows = array_splice($total_rows, 0, -1) + $shipping_tax_row + array_splice($total_rows, -1);
}
}
foreach ($recurring_taxes as $index => $tax) {
if (!$tax['compound']) {
continue;
}
if (isset($tax['name'])) {
// WC 2.0+
$tax_key = sanitize_title($tax['name']);
$tax_name = $tax['name'];
$tax_amount = $tax['tax_amount'];
$shipping_tax = $tax['shipping_tax_amount'];
if ($tax['tax_amount'] > 0) {
foreach ($order_taxes as $order_tax) {
if ($tax_name == $order_tax['name']) {
$order_tax_amount = isset($order_tax['tax_amount']) ? $order_tax['tax_amount'] + $order_tax['shipping_tax_amount'] : '';
}
}
$recurring_tax = isset($tax['tax_amount']) ? $tax['tax_amount'] + $tax['shipping_tax_amount'] : '';
}
} else {
//.........这里部分代码省略.........