当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Subscriptions_Product::get_price_string方法代码示例

本文整理汇总了PHP中WC_Subscriptions_Product::get_price_string方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Product::get_price_string方法的具体用法?PHP WC_Subscriptions_Product::get_price_string怎么用?PHP WC_Subscriptions_Product::get_price_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Subscriptions_Product的用法示例。


在下文中一共展示了WC_Subscriptions_Product::get_price_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_recurring_price_html_component

 /**
  * 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;
 }
开发者ID:alexbaron50,项目名称:Rockk3rs-Lab-Test,代码行数:14,代码来源:class-wc-pb-helpers.php

示例2: get_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;
 }
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:13,代码来源:class-wc-product-subscription.php

示例3: get_product_subtotal

 /**
  * 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;
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:14,代码来源:class-wc-subscriptions-cart.php

示例4: get_formatted_line_total

 /**
  * 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;
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:14,代码来源:class-wc-subscriptions-order.php

示例5: get_price_html

 /**
  * 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);
 }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:45,代码来源:class-wc-product-variable-subscription.php

示例6: get_price_html

 /**
  * 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));
 }
开发者ID:keshvenderg,项目名称:cloudshop,代码行数:10,代码来源:class-wc-product-subscription-variation.php

示例7: get_formatted_product_subtotal

 /**
  * 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;
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:26,代码来源:class-wc-subscriptions-cart.php

示例8: filter_price_html

 /**
  * 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('&ndash; or subscribe %s', '&ndash; or subscribe %s', count($subscription_schemes), WCS_ATT::TEXT_DOMAIN), $from_price) . '</small>';
             } else {
                 $suffix = ' <small class="wcsatt-sub-options">' . sprintf(_n('&ndash; subscription plan available', '&ndash; 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;
 }
开发者ID:VictorArgote,项目名称:woocommerce-subscribe-to-all-the-things,代码行数:86,代码来源:class-wcsatt-display.php

示例9: cart_product_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;
 }
开发者ID:slavic18,项目名称:cats,代码行数:12,代码来源:class-wc-subscriptions-cart.php

示例10: get_formatted_cart_subtotal

 /**
  * 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;
 }
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:34,代码来源:class-wc-subscriptions-cart.php

示例11: apply_subs_price_html

 /**
  * 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;
 }
开发者ID:puppy09,项目名称:madC,代码行数:43,代码来源:class-wc-product-bundle.php

示例12: print_price_fields

 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));
//.........这里部分代码省略.........
开发者ID:baden03,项目名称:access48,代码行数:101,代码来源:class-tm-extra-product-options.php

示例13: get_subscription_terms

 /**
  * 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 = '&nbsp;';
     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;
 }
开发者ID:slavic18,项目名称:cats,代码行数:36,代码来源:class-wc-name-your-price-helpers.php

示例14: filter_price_html

 /**
  * 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&#37; 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('&ndash; or subscribe %s', '&ndash; 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('&ndash; subscription available', '&ndash; 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;
 }
开发者ID:seb86,项目名称:woocommerce-subscribe-to-all-the-things,代码行数:87,代码来源:class-wcsatt-display.php

示例15: filter_price_html

 /**
  * 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;
 }
开发者ID:titocalabrese,项目名称:woocommerce-subscribe-to-all-the-things,代码行数:33,代码来源:class-wcsatt-display.php


注:本文中的WC_Subscriptions_Product::get_price_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。