/** * Returns the recurring price component of a subscription product. * * @param WC_Product $product * @return string */ public static function get_recurring_price_html_component($product) { $sync_date = $product->subscription_payment_sync_date; $product->subscription_payment_sync_date = 0; $sub_price_html = WC_Subscriptions_Product::get_price_string($product, array('price' => '%s', 'sign_up_fee' => false)); $product->subscription_payment_sync_date = $sync_date; return $sub_price_html; }
/** * Get subscription's price HTML. * * @return string containing the formatted price */ public function get_price_html($price = '') { $price = parent::get_price_html($price); if (!empty($price)) { $price = WC_Subscriptions_Product::get_price_string($this, array('price' => $price)); } return $price; }
/** * Returns the subtotal for a cart item including the subscription period and duration details * * @since 1.0 */ public static function get_product_subtotal($product_subtotal, $product) { global $woocommerce; if (WC_Subscriptions_Product::is_subscription($product)) { $exclude_tax = $woocommerce->cart->display_cart_ex_tax && $woocommerce->cart->prices_include_tax ? 'exclude_tax' : ''; $product_subtotal = '<span class="subscription-price">' . WC_Subscriptions_Product::get_price_string($product, array('price' => $product_subtotal, 'tax_calculation' => $exclude_tax)) . '</span>'; } return $product_subtotal; }
/** * Appends the subscription period/duration string to order total * * @since 1.0 */ public static function get_formatted_line_total($formatted_total, $item, $order) { if (WC_Subscriptions_Product::is_subscription($item['id'])) { $include = self::is_renewal($order) ? array('sign_up_fee' => false) : array(); $include['price'] = $formatted_total; $formatted_total = WC_Subscriptions_Product::get_price_string($item['id'], $include); } return $formatted_total; }
/** * Returns the price in html format. * * @access public * @param string $price (default: '') * @return string */ public function get_price_html($price = '') { $price = parent::get_price_html($price); if (!isset($this->subscription_period) || !isset($this->subscription_period_interval) || !isset($this->max_variation_period) || !isset($this->max_variation_period_interval)) { $this->variable_product_sync(); } // Only create the subscription price string when a price has been set if ($this->subscription_price !== '' || $this->subscription_sign_up_fee !== '') { $price = ''; if ($this->is_on_sale() && isset($this->min_variation_price) && $this->min_variation_regular_price !== $this->get_price()) { if (!$this->min_variation_price || $this->min_variation_price !== $this->max_variation_price) { $price .= $this->get_price_html_from_text(); } $variation_id = get_post_meta($this->id, '_min_price_variation_id', true); $variation = $this->get_child($variation_id); $tax_display_mode = get_option('woocommerce_tax_display_shop'); $sale_price = $tax_display_mode == 'incl' ? $variation->get_price_including_tax(1, get_post_meta($variation_id, '_sale_price', true)) : $variation->get_price_excluding_tax(1, get_post_meta($variation_id, '_sale_price', true)); $regular_price = $tax_display_mode == 'incl' ? $variation->get_price_including_tax(1, get_post_meta($variation_id, '_regular_price', true)) : $variation->get_price_excluding_tax(1, get_post_meta($variation_id, '_regular_price', true)); $price .= $this->get_price_html_from_to($regular_price, $sale_price); } else { if ($this->min_variation_price !== $this->max_variation_price) { $price .= $this->get_price_html_from_text(); } $price .= wc_price($this->get_variation_price('min', true)); } // Make sure the price contains "From:" when billing schedule differs between variations if (false === strpos($price, $this->get_price_html_from_text())) { if ($this->subscription_period !== $this->max_variation_period) { $price = $this->get_price_html_from_text() . $price; } elseif ($this->subscription_period_interval !== $this->max_variation_period_interval) { $price = $this->get_price_html_from_text() . $price; } } $price .= $this->get_price_suffix(); $price = WC_Subscriptions_Product::get_price_string($this, array('price' => $price)); } return apply_filters('woocommerce_variable_subscription_price_html', $price, $this); }
/** * Get variation price HTML. Prices are not inherited from parents. * * @return string containing the formatted price */ public function get_price_html($price = '') { $price = parent::get_price_html($price = ''); return WC_Subscriptions_Product::get_price_string($this, array('price' => $price)); }
/** * Returns the subtotal for a cart item including the subscription period and duration details * * @since 1.0 */ public static function get_formatted_product_subtotal($product_subtotal, $product, $quantity, $cart) { global $woocommerce; if (WC_Subscriptions_Product::is_subscription($product) && !self::cart_contains_subscription_renewal('child')) { // Avoid infinite loop remove_filter('woocommerce_cart_product_subtotal', __CLASS__ . '::get_formatted_product_subtotal', 11, 4); add_filter('woocommerce_get_price', array(&$product, 'get_sign_up_fee'), 100, 0); // And get the appropriate sign up fee string $sign_up_fee_string = $cart->get_product_subtotal($product, $quantity); remove_filter('woocommerce_get_price', array(&$product, 'get_sign_up_fee'), 100, 0); $product_subtotal = WC_Subscriptions_Product::get_price_string($product, array('price' => $product_subtotal, 'sign_up_fee' => $sign_up_fee_string)); if (false !== strpos($product_subtotal, $woocommerce->countries->inc_tax_or_vat())) { $product_subtotal = str_replace($woocommerce->countries->inc_tax_or_vat(), '', $product_subtotal) . ' <small class="tax_label">' . $woocommerce->countries->inc_tax_or_vat() . '</small>'; } if (false !== strpos($product_subtotal, $woocommerce->countries->ex_tax_or_vat())) { $product_subtotal = str_replace($woocommerce->countries->ex_tax_or_vat(), '', $product_subtotal) . ' <small class="tax_label">' . $woocommerce->countries->ex_tax_or_vat() . '</small>'; } $product_subtotal = '<span class="subscription-price">' . $product_subtotal . '</span>'; } return $product_subtotal; }
/** * Add subscription price string info to products with attached subscription schemes. * * @param string $price * @param WC_Product $product * @return string */ public static function filter_price_html($price, $product) { if (self::$bypass_price_html_filter) { return $price; } $subscription_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product); $has_product_level_schemes = empty($subscription_schemes) ? false : true; if ($has_product_level_schemes) { $force_subscription = get_post_meta($product->id, '_wcsatt_force_subscription', true); if ($force_subscription === 'yes') { $subscription_scheme = current($subscription_schemes); $overridden_prices = WCS_ATT_Schemes::get_subscription_scheme_prices($product, $subscription_scheme); $suffix = ''; $_cloned = clone $product; $_cloned->is_converted_to_sub = 'yes'; $_cloned->subscription_period = $subscription_scheme['subscription_period']; $_cloned->subscription_period_interval = $subscription_scheme['subscription_period_interval']; $_cloned->subscription_length = $subscription_scheme['subscription_length']; if (!empty($overridden_prices)) { $_cloned->regular_price = $overridden_prices['regular_price']; $_cloned->price = $overridden_prices['price']; $_cloned->sale_price = $overridden_prices['sale_price']; $_cloned->subscription_price = $overridden_prices['price']; } self::$bypass_price_html_filter = true; $price = $_cloned->get_price_html(); self::$bypass_price_html_filter = false; $price = WC_Subscriptions_Product::get_price_string($_cloned, array('price' => $price)); if (count($subscription_schemes) > 1 && false === strpos($price, $_cloned->get_price_html_from_text())) { $price = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), $_cloned->get_price_html_from_text(), $price); } } else { $price_overrides_exist = WCS_ATT_Schemes::subscription_price_overrides_exist($subscription_schemes); $lowest_scheme_price = $product->price; $lowest_scheme_sale_price = $product->sale_price; $lowest_scheme_regular_price = $product->regular_price; $lowest_scheme_price_html = ''; $from_price = ''; if ($price_overrides_exist) { foreach ($subscription_schemes as $subscription_scheme) { $overridden_prices = WCS_ATT_Schemes::get_subscription_scheme_prices($product, $subscription_scheme); if (!empty($overridden_prices)) { if ($overridden_prices['price'] < $lowest_scheme_price) { $lowest_scheme_price = $overridden_prices['price']; $lowest_scheme_sale_price = $overridden_prices['sale_price']; $lowest_scheme_regular_price = $overridden_prices['regular_price']; } } } if ($lowest_scheme_price < $product->price) { $_cloned = clone $product; $_cloned->is_converted_to_sub = 'yes'; $_cloned->subscription_period = $subscription_scheme['subscription_period']; $_cloned->subscription_period_interval = $subscription_scheme['subscription_period_interval']; $_cloned->subscription_length = $subscription_scheme['subscription_length']; $_cloned->price = $lowest_scheme_price; $_cloned->sale_price = $lowest_scheme_price; $_cloned->regular_price = $lowest_scheme_regular_price; self::$bypass_price_html_filter = true; $lowest_scheme_price_html = $_cloned->get_price_html(); $lowest_scheme_price_html = WC_Subscriptions_Product::get_price_string($_cloned, array('price' => $lowest_scheme_price_html)); self::$bypass_price_html_filter = false; if (count($subscription_schemes) > 1) { $from_price = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), _x('<span class="from">from </span>', 'min-price: 1 plan available', WCS_ATT::TEXT_DOMAIN), $lowest_scheme_price_html); } else { $from_price = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), _x('<span class="for">for </span>', 'min-price: multiple plans available', WCS_ATT::TEXT_DOMAIN), $lowest_scheme_price_html); } } } if ($price_overrides_exist) { $suffix = ' <small class="wcsatt-sub-options">' . sprintf(_n('– or subscribe %s', '– or subscribe %s', count($subscription_schemes), WCS_ATT::TEXT_DOMAIN), $from_price) . '</small>'; } else { $suffix = ' <small class="wcsatt-sub-options">' . sprintf(_n('– subscription plan available', '– subscription plans available', count($subscription_schemes), WCS_ATT::TEXT_DOMAIN), $from_price) . '</small>'; } $price = sprintf(__('%1$s%2$s', 'price html sub options suffix', WCS_ATT::TEXT_DOMAIN), $price, $suffix); } } return $price; }
/** * Make sure cart product prices correctly include/exclude taxes. * * @since 1.5.8 */ public static function cart_product_price($price, $product) { if (WC_Subscriptions_Product::is_subscription($product)) { $price = WC_Subscriptions_Product::get_price_string($product, array('price' => $price, 'tax_calculation' => WC()->cart->tax_display_cart)); } return $price; }
/** * Includes the sign-up fee subtotal in the subtotal displayed in the cart. * * @since 1.2 */ public static function get_formatted_cart_subtotal($cart_subtotal, $compound, $cart) { global $woocommerce; if (self::cart_contains_subscription()) { // We're in the cart widget and totals haven't been properly calculated yet so just show the product's subscription price string if (!is_checkout() && !is_cart() && !defined('WOOCOMMERCE_CHECKOUT') && !defined('WOOCOMMERCE_CART')) { $cart_subtotal = ''; foreach ($woocommerce->cart->get_cart() as $cart_item) { $cart_subtotal .= WC_Subscriptions_Product::get_price_string($cart_item['product_id']); } } elseif ($compound) { // If the cart has compound tax, we want to show the subtotal as cart + non-compound taxes (after discount) $cart_subtotal = self::get_cart_subscription_string($cart_subtotal, self::get_recurring_cart_contents_total() + self::get_recurring_shipping_total() + self::get_recurring_taxes_total(false)); } elseif ($cart->display_totals_ex_tax || !$cart->prices_include_tax) { // Display ex tax if the option is set, or prices exclude tax $cart_subtotal = self::get_cart_subscription_string($cart_subtotal, self::get_recurring_subtotal_ex_tax()); if ($cart->tax_total > 0 && $cart->prices_include_tax) { $cart_subtotal = str_replace($woocommerce->countries->ex_tax_or_vat(), '', $cart_subtotal) . ' ' . $woocommerce->countries->ex_tax_or_vat(); } } else { // Otherwise show cart items totals only (before discount) $cart_subtotal = self::get_cart_subscription_string($cart_subtotal, self::get_recurring_subtotal()); if ($cart->tax_total > 0 && !$cart->prices_include_tax) { $cart_subtotal = str_replace($woocommerce->countries->inc_tax_or_vat(), '', $cart_subtotal) . ' ' . $woocommerce->countries->inc_tax_or_vat(); } } } return $cart_subtotal; }
/** * Apply subscriptions-related suffix. * * @return string */ public function apply_subs_price_html($price) { if (!empty($this->bundled_items)) { $subs_details = array(); $non_optional_subs_exist = false; foreach ($this->bundled_items as $bundled_item_id => $bundled_item) { if ($bundled_item->is_sub()) { $bundled_item->add_price_filters(); add_filter('woocommerce_subscriptions_product_price_string_inclusions', array($this, 'isolate_recurring_price_html'), 100); $sub_isolated_price = str_replace('<span class="subscription-details"></span>', '', $bundled_item->product->get_price_html()); remove_filter('woocommerce_subscriptions_product_price_string_inclusions', array($this, 'isolate_recurring_price_html'), 100); $sub_price_html = WC_Subscriptions_Product::get_price_string($bundled_item->product, array('price' => $sub_isolated_price, 'sign_up_fee' => false, 'subscription_length' => false, 'trial_length' => false)); if ($bundled_item->is_optional()) { $style = 'style="display:none"'; } else { $non_optional_subs_exist = true; $style = ''; } if (count($subs_details) > 0) { $plus = '<span class="plus"> + </span>'; } else { $plus = ''; } $subs_details[] = '<span class="bundled_sub_price_html bundled_sub_price_html_' . $bundled_item_id . '"' . $style . '>' . $plus . $sub_price_html . '</span>'; $bundled_item->remove_price_filters(); } } if (sizeof($subs_details)) { $subs_details_html = implode('', $subs_details); if ($this->min_bundle_regular_price != 0) { $price = sprintf(_x('%1$s<span class="bundled_subscriptions_price_html" %2$s> now,</br>then %3$s</span>', 'subscription price html suffix', 'woocommerce-product-bundles'), $price, $non_optional_subs_exist ? '' : 'style="display:none"', $subs_details_html); } else { $price = '<span class="bundled_subscriptions_price_html">' . $subs_details_html . '</span>'; } } } return $price; }
private function print_price_fields($product_id = 0, $form_prefix = "") { if (!$product_id) { global $product; if ($product) { $product_id = $product->id; } } else { $product = wc_get_product($product_id); } if (!$product_id || empty($product)) { if (!empty($this->current_product_id_to_be_displayed)) { $product_id = $this->current_product_id_to_be_displayed; $product = wc_get_product($product_id); } else { $this->tm_epo_totals_batch($form_prefix); return; } } if (!$product_id || empty($product)) { return; } $cpf_price_array = $this->get_product_tm_epos($product_id); if (!$cpf_price_array) { return; } if ($cpf_price_array && $this->tm_epo_enable_final_total_box_all == "no") { $global_price_array = $cpf_price_array['global']; $local_price_array = $cpf_price_array['local']; if (empty($global_price_array) && empty($local_price_array)) { return; } } if (!$cpf_price_array && $this->tm_epo_enable_final_total_box_all == "no") { return; } if ($form_prefix) { $form_prefix = "_" . $form_prefix; } // WooCommerce Dynamic Pricing & Discounts if (class_exists('RP_WCDPD') && !empty($GLOBALS['RP_WCDPD'])) { $price = $this->get_RP_WCDPD($product); if ($price) { $price['product'] = array(); if ($price['is_multiprice']) { foreach ($price['rules'] as $variation_id => $variation_rule) { foreach ($variation_rule as $rulekey => $pricerule) { $price['product'][$variation_id][] = array("min" => $pricerule["min"], "max" => $pricerule["max"], "value" => $pricerule["type"] != "percentage" ? apply_filters('woocommerce_tm_epo_price', $pricerule["value"], "", false) : $pricerule["value"], "type" => $pricerule["type"]); } } } else { foreach ($price['rules'] as $rulekey => $pricerule) { $price['product'][0][] = array("min" => $pricerule["min"], "max" => $pricerule["max"], "value" => $pricerule["type"] != "percentage" ? apply_filters('woocommerce_tm_epo_price', $pricerule["value"], "", false) : $pricerule["value"], "type" => $pricerule["type"]); } } } else { $price = array(); $price['product'] = array(); } $price['price'] = apply_filters('woocommerce_tm_epo_price', $product->get_price(), "", false); } else { if (class_exists('WC_Dynamic_Pricing')) { $id = isset($product->variation_id) ? $product->variation_id : $product->id; $dp = WC_Dynamic_Pricing::instance(); if ($dp && is_object($dp) && property_exists($dp, "discounted_products") && isset($dp->discounted_products[$id])) { $_price = $dp->discounted_products[$id]; } else { $_price = $product->get_price(); } } else { $_price = apply_filters('woocommerce_tm_epo_price_compatibility', $product->get_price(), $product); } $price = array(); $price['product'] = array(); $price['price'] = apply_filters('woocommerce_tm_epo_price', $_price, "", false); } $variations = array(); $variations_subscription_period = array(); $variations_subscription_sign_up_fee = array(); foreach ($product->get_children() as $child_id) { $variation = $product->get_child($child_id); if (!$variation->exists()) { continue; } if (class_exists('WC_Subscriptions_Product')) { $variations_subscription_period[$child_id] = WC_Subscriptions_Product::get_price_string($variation, array('subscription_price' => false, 'sign_up_fee' => false, 'trial_length' => false)); $variations_subscription_sign_up_fee[$child_id] = $variation->subscription_sign_up_fee; } else { $variations_subscription_period[$child_id] = ''; $variations_subscription_sign_up_fee[$child_id] = ''; } $variations[$child_id] = apply_filters('woocommerce_tm_epo_price_compatibility', apply_filters('woocommerce_tm_epo_price', $variation->get_price(), "", false), $variation, $child_id); } $is_subscription = false; $subscription_period = ''; $subscription_sign_up_fee = 0; if (class_exists('WC_Subscriptions_Product')) { if (WC_Subscriptions_Product::is_subscription($product)) { $is_subscription = true; $subscription_period = WC_Subscriptions_Product::get_price_string($product, array('subscription_price' => false, 'sign_up_fee' => false, 'trial_length' => false)); $subscription_sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product); } } global $woocommerce; $cart = $woocommerce->cart; $_tax = new WC_Tax(); $taxrates = $_tax->get_rates($product->get_tax_class()); unset($_tax); $tax_rate = 0; foreach ($taxrates as $key => $value) { $tax_rate = $tax_rate + floatval($value['rate']); } $taxable = $product->is_taxable(); $tax_display_mode = get_option('woocommerce_tax_display_shop'); $tax_string = ""; if ($taxable && $this->tm_epo_global_tax_string_suffix == "yes") { if ($tax_display_mode == 'excl') { //if ( $cart->tax_total > 0 && $cart->prices_include_tax ) { $tax_string = ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>'; //} } else { //if ( $cart->tax_total > 0 && !$cart->prices_include_tax ) { $tax_string = ' <small>' . WC()->countries->inc_tax_or_vat() . '</small>'; //} } } $force_quantity = 0; if ($this->cart_edit_key) { $cart_item_key = $this->cart_edit_key; $cart_item = WC()->cart->get_cart_item($cart_item_key); if (isset($cart_item["quantity"])) { $force_quantity = $cart_item["quantity"]; } } if (!$this->is_bto) { if (empty($this->epo_internal_counter) || !isset($this->epo_internal_counter_check["tc" . $this->epo_internal_counter])) { // First time displaying totals and fields haven't been displayed $this->epo_internal_counter++; $this->epo_internal_counter_check["tc" . $this->epo_internal_counter] = $this->epo_internal_counter; } else { // Fields have already been displayed unset($this->epo_internal_counter_check["tc" . $this->epo_internal_counter]); $this->current_product_id_to_be_displayed = 0; } $_epo_internal_counter = $this->epo_internal_counter; } else { $_epo_internal_counter = 0; } wc_get_template('tm-totals.php', array('theme_name' => $this->get_theme('Name'), 'variations' => esc_html(json_encode((array) $variations)), 'variations_subscription_period' => esc_html(json_encode((array) $variations_subscription_period)), 'variations_subscription_sign_up_fee' => esc_html(json_encode((array) $variations_subscription_sign_up_fee)), 'subscription_period' => $subscription_period, 'subscription_sign_up_fee' => $subscription_sign_up_fee, 'is_subscription' => $is_subscription, 'is_sold_individually' => $product->is_sold_individually(), 'hidden' => $this->tm_meta_cpf['override_final_total_box'] ? $this->tm_epo_final_total_box == 'hide' ? ' hidden' : '' : ($this->tm_meta_cpf['override_final_total_box'] == 'hide' ? ' hidden' : ''), 'form_prefix' => $form_prefix, 'type' => esc_html($product->product_type), 'price' => esc_html(is_object($product) ? apply_filters('woocommerce_tm_final_price', $price['price'], $product) : ''), 'taxable' => $taxable, 'tax_display_mode' => $tax_display_mode, 'prices_include_tax' => $cart->prices_include_tax, 'tax_rate' => $tax_rate, 'tax_string' => $tax_string, 'product_price_rules' => esc_html(json_encode((array) $price['product'])), 'fields_price_rules' => $this->tm_epo_dpd_enable == "no" ? 0 : 1, 'tm_epo_dpd_suffix' => $this->tm_epo_dpd_suffix, 'tm_epo_dpd_prefix' => $this->tm_epo_dpd_prefix, 'force_quantity' => $force_quantity, 'product_id' => $product_id, 'epo_internal_counter' => $_epo_internal_counter), $this->_namespace, $this->template_path); }
/** * Generate Markup for Subscription Periods * * @param string $input * @param obj $product * @return string * @access public * @since 2.0 */ public static function get_subscription_terms($input = '', $product) { $terms = ' '; if (!is_object($product)) { $product = wc_nyp_get_product($product); } // parent variable subscriptions don't have a billing period, so we get a array to string notice. therefore only apply to simple subs and sub variations if ($product->is_type('subscription') || $product->is_type('subscription_variation')) { if (self::is_billing_period_variable($product)) { // don't display the subscription price, period or length $include = array('price' => '', 'subscription_price' => false, 'subscription_period' => false); } else { $include = array('price' => '', 'subscription_price' => false); // if we don't show the price we don't get the "per" backslash so add it back if (WC_Subscriptions_Product::get_interval($product) == 1) { $terms .= '<span class="per">/ </span>'; } } $terms .= WC_Subscriptions_Product::get_price_string($product, $include); } // piece it all together - JS needs a span with this class to change terms on variation found event // use details class to mimic Subscriptions plugin, leave terms class for backcompat if ('woocommerce_get_price_input' == current_filter()) { $terms = '<span class="subscription-details subscription-terms">' . $terms . '</span>'; } return $input . $terms; }
/** * Adds subscription price string info to products with attached subscription schemes. * * @param string $price * @param WC_Product $product * @return string */ public static function filter_price_html($price, $product) { if (self::$bypass_price_html_filter) { return $price; } if ($product->get_price() === '') { return $price; } $product_level_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product); if (!empty($product_level_schemes)) { $has_variable_price = false; $subscription_scheme = current($product_level_schemes); if ($price_overrides_exist = WCS_ATT_Scheme_Prices::subscription_price_overrides_exist($product_level_schemes)) { $lowest_scheme_price_data = WCS_ATT_Scheme_Prices::get_lowest_price_subscription_scheme_data($product, $product_level_schemes); $subscription_scheme = $lowest_scheme_price_data['scheme']; } // Reinstantiate variable products to re-populate a filtered version of the 'prices_array' property. Otherwise, a clone should do... but re-instantiate just in case. $_product = wc_get_product($product->id); // ...and let this be filterable. $_product = apply_filters('wcsatt_overridden_subscription_prices_product', $_product, $subscription_scheme, $product); $_product->is_converted_to_sub = 'yes'; $_product->subscription_period = isset($subscription_scheme['subscription_period']) ? $subscription_scheme['subscription_period'] : ''; $_product->subscription_period_interval = isset($subscription_scheme['subscription_period_interval']) ? $subscription_scheme['subscription_period_interval'] : ''; $_product->subscription_length = isset($subscription_scheme['subscription_length']) ? $subscription_scheme['subscription_length'] : ''; // Add price method filters. WCS_ATT_Scheme_Prices::add_price_filters($_product, $subscription_scheme); if (count($product_level_schemes) > 1) { $has_variable_price = true; } else { if ('variable' === $product->product_type && $_product->get_variation_price('min') !== $_product->get_variation_price('max')) { $has_variable_price = true; // If all variations prices are overridden, they will be equal. if (isset($subscription_scheme['subscription_pricing_method']) && $subscription_scheme['subscription_pricing_method'] === 'override') { $has_variable_price = false; } } elseif ('bundle' === $product->product_type && $product->get_bundle_price('min') !== $product->get_bundle_price('max')) { $has_variable_price = true; } elseif ('composite' === $product->product_type && $product->get_composite_price('min') !== $product->get_composite_price('max')) { $has_variable_price = true; } } $force_subscription = get_post_meta($product->id, '_wcsatt_force_subscription', true); if ($force_subscription === 'yes') { self::$bypass_price_html_filter = true; $price = $_product->get_price_html(); self::$bypass_price_html_filter = false; $price = WC_Subscriptions_Product::get_price_string($_product, array('price' => $price)); if ($has_variable_price && false === strpos($price, $_product->get_price_html_from_text())) { $price = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), $_product->get_price_html_from_text(), $price); } } else { $suffix_price_html = ''; // Discount format vs Price format. Experimental use only. if (apply_filters('wcsatt_price_html_discount_format', false, $product) && WCS_ATT_Scheme_Prices::has_subscription_price_override($subscription_scheme) && $subscription_scheme['subscription_pricing_method'] === 'inherit') { $discount = $subscription_scheme['subscription_discount']; $discount_html = '</small> <span class="wcsatt-sub-discount">' . sprintf(__('%s% off', WCS_ATT::TEXT_DOMAIN), $discount) . '</span><small>'; $suffix_price_html = sprintf(__('at%1$s%2$s', WCS_ATT::TEXT_DOMAIN), $has_variable_price ? __(' up to', WCS_ATT::TEXT_DOMAIN) : '', $discount_html); } else { self::$bypass_price_html_filter = true; $lowest_scheme_price_html = $_product->get_price_html(); self::$bypass_price_html_filter = false; $lowest_scheme_price_data = isset($lowest_scheme_price_data) ? $lowest_scheme_price_data : array(); $lowest_scheme_price_html = WC_Subscriptions_Product::get_price_string($_product, apply_filters('wcsatt_get_single_product_lowest_price_string', array('price' => $lowest_scheme_price_html), $lowest_scheme_price_data)); if ($has_variable_price) { $suffix_price_html = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), _x('<span class="from">from </span>', 'subscribe from price', WCS_ATT::TEXT_DOMAIN), str_replace($_product->get_price_html_from_text(), '', $lowest_scheme_price_html)); } else { $suffix_price_html = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), _x('<span class="for">for </span>', 'subscribe for price', WCS_ATT::TEXT_DOMAIN), $lowest_scheme_price_html); } } if ($price_overrides_exist) { $suffix = ' <small class="wcsatt-sub-options">' . sprintf(_n('– or subscribe %s', '– subscription plans available %s', count($product_level_schemes), WCS_ATT::TEXT_DOMAIN), $suffix_price_html) . '</small>'; } else { $suffix = ' <small class="wcsatt-sub-options">' . sprintf(_n('– subscription available', '– subscription plans available', count($product_level_schemes), WCS_ATT::TEXT_DOMAIN), $suffix_price_html) . '</small>'; } $price = sprintf(_x('%1$s%2$s', 'price html sub options suffix', WCS_ATT::TEXT_DOMAIN), $price, $suffix); } WCS_ATT_Scheme_Prices::remove_price_filters(); } return $price; }
/** * Add subscription price string info to products with attached subscription schemes. * * @param string $price * @param WC_Product $product * @return string */ public static function filter_price_html($price, $product) { $subscription_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product); $has_product_level_schemes = empty($subscription_schemes) ? false : true; if ($has_product_level_schemes) { $force_subscription = get_post_meta($product->id, '_wcsatt_force_subscription', true); if ($force_subscription === 'yes') { $subscription_scheme = current($subscription_schemes); $suffix = ''; if (count($subscription_schemes) > 1) { $suffix = ' <small class="wcsatt-sub-options">' . __('(additional subscription options available)', WCS_ATT::TEXT_DOMAIN) . '</small>'; } $_cloned = clone $product; $_cloned->is_converted_to_sub = 'yes'; $_cloned->subscription_period = $subscription_scheme['subscription_period']; $_cloned->subscription_period_interval = $subscription_scheme['subscription_period_interval']; $_cloned->subscription_length = $subscription_scheme['subscription_length']; $price = WC_Subscriptions_Product::get_price_string($_cloned, array('price' => $price)); $price = sprintf(__('%1$s%2$s', 'price html sub options suffix', WCS_ATT::TEXT_DOMAIN), $price, $suffix); } else { $suffix = ' <small class="wcsatt-sub-options">' . __('(also available as subscription)', WCS_ATT::TEXT_DOMAIN) . '</small>'; $price = sprintf(__('%1$s%2$s', 'price html sub options suffix', WCS_ATT::TEXT_DOMAIN), $price, $suffix); } } return $price; }