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


PHP WC_Subscriptions::get_longest_period方法代码示例

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


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

示例1: variable_product_sync

 /**
  * Sync variable product prices with the childs lowest/highest prices.
  *
  * @access public
  * @return void
  */
 public function variable_product_sync($product_id = '')
 {
     global $woocommerce;
     parent::variable_product_sync();
     $children = get_posts(array('post_parent' => $this->id, 'posts_per_page' => -1, 'post_type' => 'product_variation', 'fields' => 'ids', 'post_status' => 'publish'));
     $lowest_initial_amount = $highest_initial_amount = $lowest_price = $highest_price = '';
     $shortest_initial_period = $longest_initial_period = $shortest_trial_period = $longest_trial_period = $shortest_trial_length = $longest_trial_length = '';
     $longest_initial_interval = $shortest_initial_interval = $variable_subscription_period = $variable_subscription_period_interval = '';
     $lowest_regular_price = $highest_regular_price = $lowest_sale_price = $highest_sale_price = $max_subscription_period = $max_subscription_period_interval = '';
     $variable_subscription_sign_up_fee = $variable_subscription_trial_period = $variable_subscription_trial_length = $variable_subscription_length = $variable_subscription_sign_up_fee = $variable_subscription_trial_period = $variable_subscription_trial_length = $variable_subscription_length = '';
     $min_variation_id = $max_variation_id = NULL;
     if ($children) {
         foreach ($children as $child) {
             $is_max = $is_min = false;
             // WC has already determined the correct price which accounts for sale price
             $child_price = get_post_meta($child, '_price', true);
             $child_billing_period = get_post_meta($child, '_subscription_period', true);
             $child_billing_interval = get_post_meta($child, '_subscription_period_interval', true);
             $child_sign_up_fee = get_post_meta($child, '_subscription_sign_up_fee', true);
             $child_free_trial_length = get_post_meta($child, '_subscription_trial_length', true);
             $child_free_trial_period = get_post_meta($child, '_subscription_trial_period', true);
             if ($child_price === '' && $child_sign_up_fee === '') {
                 continue;
             }
             $child_price = $child_price === '' ? 0 : $child_price;
             $child_sign_up_fee = $child_sign_up_fee === '' ? 0 : $child_sign_up_fee;
             $has_free_trial = $child_free_trial_length !== '' && $child_free_trial_length > 0 ? true : false;
             // Determine some recurring price flags
             $is_lowest_price = $child_price < $lowest_price || '' === $lowest_price ? true : false;
             $is_longest_period = $child_billing_period === WC_Subscriptions::get_longest_period($variable_subscription_period, $child_billing_period) ? true : false;
             $is_longest_interval = $child_billing_interval >= $variable_subscription_period_interval || '' === $variable_subscription_period_interval ? true : false;
             // Find the amount the subscriber will have to pay up-front
             if ($has_free_trial) {
                 $initial_amount = $child_sign_up_fee;
                 $initial_period = $child_free_trial_period;
                 $initial_interval = $child_free_trial_length;
             } else {
                 $initial_amount = $child_price + $child_sign_up_fee;
                 $initial_period = $child_billing_period;
                 $initial_interval = $child_billing_interval;
             }
             // We have a free trial & no sign-up fee, so need to choose the longest free trial (and maybe the shortest)
             if ($has_free_trial && $child_sign_up_fee == 0) {
                 // First variation
                 if ('' === $longest_trial_period) {
                     $is_min = true;
                     // If two variations have the same free trial, choose the variation with the lowest recurring price for the longest period
                 } elseif ($variable_subscription_trial_period === $child_free_trial_period && $child_free_trial_length === $variable_subscription_trial_length) {
                     // If the variation has the lowest recurring price, it's the cheapest
                     if ($is_lowest_price) {
                         $is_min = true;
                         // When current variation's free trial is the same as the lowest, it's the cheaper if it has a longer billing schedule
                     } elseif ($child_price === $lowest_price) {
                         if ($is_longest_period && $is_longest_interval) {
                             $is_min = true;
                             // Longest with a new billing period
                         } elseif ($is_longest_period && $child_billing_period !== $variable_subscription_trial_period) {
                             $is_min = true;
                         }
                     }
                     // Otherwise the cheapest variation is the one with the longer trial
                 } elseif ($variable_subscription_trial_period === $child_free_trial_period) {
                     $is_min = $child_free_trial_length > $variable_subscription_trial_length ? true : false;
                     // Otherwise just a longer trial period (that isn't equal to the longest period)
                 } elseif ($child_free_trial_period === WC_Subscriptions::get_longest_period($longest_trial_period, $child_free_trial_period)) {
                     $is_min = true;
                 }
                 if ($is_min) {
                     $longest_trial_period = $child_free_trial_period;
                     $longest_trial_length = $child_free_trial_length;
                 }
                 // If the current cheapest variation is also free then the shortest trial period is the most expensive
                 if (0 == $lowest_price || '' === $lowest_price) {
                     if ('' === $shortest_trial_period) {
                         $is_max = true;
                         // Need to check trial length
                     } elseif ($shortest_trial_period === $child_free_trial_period) {
                         $is_max = $child_free_trial_length < $shortest_trial_length ? true : false;
                         // Need to find shortest period
                     } elseif ($child_free_trial_period === WC_Subscriptions::get_shortest_period($shortest_trial_period, $child_free_trial_period)) {
                         $is_max = true;
                     }
                     if ($is_max) {
                         $shortest_trial_period = $child_free_trial_period;
                         $shortest_trial_length = $child_free_trial_length;
                     }
                 }
             } else {
                 $longest_initial_period = WC_Subscriptions::get_longest_period($longest_initial_period, $initial_period);
                 $shortest_initial_period = WC_Subscriptions::get_shortest_period($shortest_initial_period, $initial_period);
                 $is_lowest_initial_amount = $initial_amount < $lowest_initial_amount || '' === $lowest_initial_amount ? true : false;
                 $is_longest_initial_period = $initial_period === $longest_initial_period ? true : false;
                 $is_longest_initial_interval = $initial_interval >= $longest_initial_interval || '' === $longest_initial_interval ? true : false;
                 $is_highest_initial = $initial_amount > $highest_initial_amount || '' === $highest_initial_amount ? true : false;
//.........这里部分代码省略.........
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:101,代码来源:class-wc-product-variable-subscription.php


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