• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WC_Subscriptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: add_view_subscription_template

 /**
  * Show the subscription template when view a subscription instead of loading the default order template.
  *
  * @param $located
  * @param $template_name
  * @param $args
  * @param $template_path
  * @param $default_path
  * @since 2.0
  */
 public static function add_view_subscription_template($located, $template_name, $args, $template_path, $default_path)
 {
     global $wp;
     if ('myaccount/my-account.php' == $template_name && !empty($wp->query_vars['view-subscription']) && WC_Subscriptions::is_woocommerce_pre('2.6')) {
         $located = wc_locate_template('myaccount/view-subscription.php', $template_path, plugin_dir_path(WC_Subscriptions::$plugin_file) . 'templates/');
     }
     return $located;
 }
开发者ID:DustinHartzler,项目名称:TheCLEFT,代码行数:18,代码来源:class-wcs-template-loader.php


示例2: hook_transactional_emails

 /**
  * Hooks up all of Skip One transaction emails after the WooCommerce object is constructed.
  *
  * @since 1.0.0
  * @access public
  * @static
  */
 public static function hook_transactional_emails()
 {
     // Don't send subscription
     if (WC_Subscriptions::is_duplicate_site() && !defined('WCS_FORCE_EMAIL')) {
         return;
     }
     $skip_emails = array('next_payment_date');
     foreach ($skip_emails as $email) {
         add_action('woocommerce_skip_one_' . $email, __CLASS__ . '::send_' . $email . '_email', 10, 2);
     }
 }
开发者ID:AnimalsCode,项目名称:WooCommerce-Skip-One,代码行数:18,代码来源:class-wcso-subscriptions-email.php


示例3: hook_transactional_emails

 /**
  * Hooks up all of Subscription's transaction emails after the WooCommerce object is constructed.
  *
  * @since 1.4
  */
 public static function hook_transactional_emails()
 {
     // Don't send subscription
     if (WC_Subscriptions::is_duplicate_site() && !defined('WCS_FORCE_EMAIL')) {
         return;
     }
     add_action('woocommerce_subscription_status_updated', __CLASS__ . '::send_cancelled_email', 10, 2);
     $order_email_actions = array('woocommerce_order_status_pending_to_processing', 'woocommerce_order_status_pending_to_completed', 'woocommerce_order_status_pending_to_on-hold', 'woocommerce_order_status_failed_to_processing_notification', 'woocommerce_order_status_failed_to_completed_notification', 'woocommerce_order_status_failed_to_on-hold_notification', 'woocommerce_order_status_completed', 'woocommerce_generated_manual_renewal_order', 'woocommerce_order_status_failed');
     foreach ($order_email_actions as $action) {
         add_action($action, __CLASS__ . '::maybe_remove_woocommerce_email', 9);
         add_action($action, __CLASS__ . '::send_renewal_order_email', 10);
         add_action($action, __CLASS__ . '::send_switch_order_email', 10);
         add_action($action, __CLASS__ . '::maybe_reattach_woocommerce_email', 11);
     }
 }
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:20,代码来源:class-wc-subscriptions-email.php


示例4: __construct

 /**
  * Create a simple subscription product object.
  *
  * @access public
  * @param mixed $product
  */
 public function __construct($product, $args = array())
 {
     parent::__construct($product, $args = array());
     $this->parent_product_type = $this->product_type;
     $this->product_type = 'subscription_variation';
     $this->subscription_variation_level_meta_data = array('subscription_price' => 0, 'subscription_period' => '', 'subscription_period_interval' => 'day', 'subscription_length' => 0, 'subscription_trial_length' => 0, 'subscription_trial_period' => 'day', 'subscription_sign_up_fee' => 0, 'subscription_payment_sync_date' => 0);
     if (WC_Subscriptions::is_woocommerce_pre_2_2()) {
         // WC 2.1
         // Convert selected subscription meta fields for easy access
         foreach ($this->subscription_variation_level_meta_data as $meta_key => $default_value) {
             if (!empty($this->product_custom_fields['_' . $meta_key][0])) {
                 $this->{$meta_key} = maybe_unserialize($this->product_custom_fields['_' . $meta_key][0]);
             } else {
                 $this->{$meta_key} = $this->subscription_variation_level_meta_data[$meta_key];
             }
         }
     } else {
         $this->variation_level_meta_data = array_merge($this->variation_level_meta_data, $this->subscription_variation_level_meta_data);
     }
 }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:26,代码来源:class-wc-product-subscription-variation.php


示例5: add_order_meta

 /**
  * When a new order is inserted, add subscriptions related order meta.
  *
  * @since 1.0
  */
 public static function add_order_meta($order_id, $posted)
 {
     global $woocommerce;
     if (!WC_Subscriptions_Cart::cart_contains_subscription_renewal('child') && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
         // This works because the 'woocommerce_add_order_item_meta' runs before the 'woocommerce_checkout_update_order_meta' hook
         // Set the recurring totals so totals display correctly on order page
         update_post_meta($order_id, '_order_recurring_discount_cart', WC_Subscriptions_Cart::get_recurring_discount_cart());
         update_post_meta($order_id, '_order_recurring_discount_cart_tax', WC_Subscriptions_Cart::get_recurring_discount_cart_tax());
         update_post_meta($order_id, '_order_recurring_discount_total', WC_Subscriptions_Cart::get_recurring_discount_total());
         update_post_meta($order_id, '_order_recurring_shipping_tax_total', WC_Subscriptions_Cart::get_recurring_shipping_tax_total());
         update_post_meta($order_id, '_order_recurring_shipping_total', WC_Subscriptions_Cart::get_recurring_shipping_total());
         update_post_meta($order_id, '_order_recurring_tax_total', WC_Subscriptions_Cart::get_recurring_total_tax());
         update_post_meta($order_id, '_order_recurring_total', WC_Subscriptions_Cart::get_recurring_total());
         // Set the recurring payment method - it starts out the same as the original by may change later
         update_post_meta($order_id, '_recurring_payment_method', get_post_meta($order_id, '_payment_method', true));
         update_post_meta($order_id, '_recurring_payment_method_title', get_post_meta($order_id, '_payment_method_title', true));
         $order = new WC_Order($order_id);
         $order_fees = $order->get_fees();
         // the fee order items have already been set, we just need to to add the recurring total meta
         $cart_fees = $woocommerce->cart->get_fees();
         foreach ($order->get_fees() as $item_id => $order_fee) {
             // Find the matching fee in the cart
             foreach ($cart_fees as $fee_index => $cart_fee) {
                 if (sanitize_title($order_fee['name']) == $cart_fee->id) {
                     woocommerce_add_order_item_meta($item_id, '_recurring_line_total', wc_format_decimal($cart_fee->recurring_amount));
                     woocommerce_add_order_item_meta($item_id, '_recurring_line_tax', wc_format_decimal($cart_fee->recurring_tax));
                     unset($cart_fees[$fee_index]);
                     break;
                 }
             }
         }
         // Get recurring taxes into same format as _order_taxes
         $order_recurring_taxes = array();
         foreach (WC_Subscriptions_Cart::get_recurring_taxes() as $tax_key => $tax_amount) {
             $item_id = woocommerce_add_order_item($order_id, array('order_item_name' => WC_Tax::get_rate_code($tax_key), 'order_item_type' => 'recurring_tax'));
             if ($item_id) {
                 wc_add_order_item_meta($item_id, 'rate_id', $tax_key);
                 wc_add_order_item_meta($item_id, 'label', WC_Tax::get_rate_label($tax_key));
                 wc_add_order_item_meta($item_id, 'compound', absint(WC_Tax::is_compound($tax_key) ? 1 : 0));
                 wc_add_order_item_meta($item_id, 'tax_amount', wc_format_decimal(isset(WC()->cart->recurring_taxes[$tax_key]) ? WC()->cart->recurring_taxes[$tax_key] : 0));
                 wc_add_order_item_meta($item_id, 'shipping_tax_amount', wc_format_decimal(isset(WC()->cart->recurring_shipping_taxes[$tax_key]) ? WC()->cart->recurring_shipping_taxes[$tax_key] : 0));
             }
         }
         $payment_gateways = $woocommerce->payment_gateways->payment_gateways();
         if ('yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no')) {
             update_post_meta($order_id, '_wcs_requires_manual_renewal', 'true');
         } elseif (isset($payment_gateways[$posted['payment_method']]) && !$payment_gateways[$posted['payment_method']]->supports('subscriptions')) {
             update_post_meta($order_id, '_wcs_requires_manual_renewal', 'true');
         }
         $cart_item = WC_Subscriptions_Cart::cart_contains_subscription_renewal();
         if (isset($cart_item['subscription_renewal']) && 'parent' == $cart_item['subscription_renewal']['role']) {
             update_post_meta($order_id, '_original_order', $cart_item['subscription_renewal']['original_order']);
         }
         // WC 2.1+
         if (!WC_Subscriptions::is_woocommerce_pre('2.1')) {
             // Recurring coupons
             if ($applied_coupons = $woocommerce->cart->get_coupons()) {
                 foreach ($applied_coupons as $code => $coupon) {
                     if (!isset($woocommerce->cart->recurring_coupon_discount_amounts[$code])) {
                         continue;
                     }
                     $item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $code, 'order_item_type' => 'recurring_coupon'));
                     // Add line item meta
                     if ($item_id) {
                         woocommerce_add_order_item_meta($item_id, 'discount_amount', isset($woocommerce->cart->recurring_coupon_discount_amounts[$code]) ? $woocommerce->cart->recurring_coupon_discount_amounts[$code] : 0);
                     }
                 }
             }
             // Add recurring shipping order items
             if (WC_Subscriptions_Cart::cart_contains_subscriptions_needing_shipping()) {
                 $packages = $woocommerce->shipping->get_packages();
                 $checkout = $woocommerce->checkout();
                 foreach ($packages as $i => $package) {
                     if (isset($package['rates'][$checkout->shipping_methods[$i]])) {
                         $method = $package['rates'][$checkout->shipping_methods[$i]];
                         $item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $method->label, 'order_item_type' => 'recurring_shipping'));
                         if ($item_id) {
                             woocommerce_add_order_item_meta($item_id, 'method_id', $method->id);
                             woocommerce_add_order_item_meta($item_id, 'cost', WC_Subscriptions::format_total($method->cost));
                             woocommerce_add_order_item_meta($item_id, 'taxes', array_map('wc_format_decimal', $method->taxes));
                             do_action('woocommerce_subscriptions_add_recurring_shipping_order_item', $order_id, $item_id, $i);
                         }
                     }
                 }
             }
             // Remove shipping on original order if it was added but is not required
             if (!WC_Subscriptions_Cart::charge_shipping_up_front()) {
                 foreach ($order->get_shipping_methods() as $order_item_id => $shipping_method) {
                     woocommerce_update_order_item_meta($order_item_id, 'cost', WC_Subscriptions::format_total(0));
                 }
             }
         } else {
             update_post_meta($order_id, '_recurring_shipping_method', get_post_meta($order_id, '_shipping_method', true), true);
             update_post_meta($order_id, '_recurring_shipping_method_title', get_post_meta($order_id, '_shipping_method_title', true), true);
         }
//.........这里部分代码省略.........
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:101,代码来源:class-wc-subscriptions-checkout.php


示例6:

        ?>
						<?php 
        echo WC_Subscriptions_Order::get_item_name($subscription_details['order_id'], $subscription_details['product_id']);
        ?>
					<?php 
        if (false !== $product) {
            ?>
					</a>
					<?php 
        }
        ?>
					<?php 
        $order_item = WC_Subscriptions_Order::get_item_by_product_id($order, $subscription_details['product_id']);
        ?>
					<?php 
        if (WC_Subscriptions::is_woocommerce_pre('2.4')) {
            ?>
						<?php 
            $item_meta = new WC_Order_Item_Meta($order_item['item_meta'], $product);
            ?>
					<?php 
        } else {
            ?>
						<?php 
            $item_meta = new WC_Order_Item_Meta($order_item, $product);
            ?>
					<?php 
        }
        ?>
					<?php 
        $meta_to_display = $item_meta->display(true, true);
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:31,代码来源:my-subscriptions.php


示例7: get_subscription_period_interval_strings

 /**
  * Return an i18n'ified associative array of all possible subscription periods.
  *
  * @since 1.0
  */
 public static function get_subscription_period_interval_strings($interval = '')
 {
     $intervals = array(1 => __('per', WC_Subscriptions::$text_domain));
     foreach (range(2, 6) as $i) {
         $intervals[$i] = sprintf(__('every %s', WC_Subscriptions::$text_domain), WC_Subscriptions::append_numeral_suffix($i));
     }
     $intervals = apply_filters('woocommerce_subscription_period_interval_strings', $intervals);
     if (empty($interval)) {
         return $intervals;
     } else {
         return $intervals[$interval];
     }
 }
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:18,代码来源:class-wc-subscriptions-manager.php


示例8: get_trial_expiration_date

 /**
  * Takes a subscription product's ID and returns the date on which the subscription trial will expire,
  * based on the subscription's trial length and calculated from either the $from_date if specified,
  * or the current date/time.
  *
  * @param int $product_id The product/post ID of the subscription
  * @param mixed $from_date A MySQL formatted date/time string from which to calculate the expiration date (in UTC timezone), or empty (default), which will use today's date/time (in UTC timezone).
  * @since 1.0
  */
 public static function get_trial_expiration_date($product_id, $from_date = '')
 {
     $trial_period = self::get_trial_period($product_id);
     $trial_length = self::get_trial_length($product_id);
     if ($trial_length > 0) {
         if (empty($from_date)) {
             $from_date = gmdate('Y-m-d H:i:s');
         }
         if ('month' == $trial_period) {
             $trial_expiration_date = date('Y-m-d H:i:s', WC_Subscriptions::add_months(strtotime($from_date), $trial_length));
         } else {
             // Safe to just add the billing periods
             $trial_expiration_date = date('Y-m-d H:i:s', strtotime("+ {$trial_length} {$trial_period}s", strtotime($from_date)));
         }
     } else {
         $trial_expiration_date = 0;
     }
     return apply_filters('woocommerce_subscriptions_product_trial_expiration_date', $trial_expiration_date, $product_id, $from_date);
 }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:28,代码来源:class-wc-subscriptions-product.php


示例9: wcs_price_string

/**
 * Creates a subscription price string from an array of subscription details. For example, "$5 / month for 12 months".
 *
 * @param array $subscription_details A set of name => value pairs for the subscription details to include in the string. Available keys:
 *		'initial_amount': The upfront payment for the subscription, including sign up fees, as a string from the @see wc_price(). Default empty string (no initial payment)
 *		'initial_description': The word after the initial payment amount to describe the amount. Examples include "now" or "initial payment". Defaults to "up front".
 *		'recurring_amount': The amount charged per period. Default 0 (no recurring payment).
 *		'subscription_interval': How regularly the subscription payments are charged. Default 1, meaning each period e.g. per month.
 *		'subscription_period': The temporal period of the subscription. Should be one of {day|week|month|year} as used by @see wcs_get_subscription_period_strings()
 *		'subscription_length': The total number of periods the subscription should continue for. Default 0, meaning continue indefinitely.
 *		'trial_length': The total number of periods the subscription trial period should continue for.  Default 0, meaning no trial period.
 *		'trial_period': The temporal period for the subscription's trial period. Should be one of {day|week|month|year} as used by @see wcs_get_subscription_period_strings()
 * @since 2.0
 * @return string The price string with translated and billing periods included
 */
function wcs_price_string($subscription_details)
{
    global $wp_locale;
    $subscription_details = wp_parse_args($subscription_details, array('currency' => '', 'initial_amount' => '', 'initial_description' => _x('up front', 'initial payment on a subscription', 'woocommerce-subscriptions'), 'recurring_amount' => '', 'subscription_interval' => 1, 'subscription_period' => '', 'subscription_length' => 0, 'trial_length' => 0, 'trial_period' => '', 'is_synced' => false, 'synchronised_payment_day' => 0, 'display_excluding_tax_label' => false));
    $subscription_details['subscription_period'] = strtolower($subscription_details['subscription_period']);
    // Make sure prices have been through wc_price()
    if (is_numeric($subscription_details['initial_amount'])) {
        $initial_amount_string = wc_price($subscription_details['initial_amount'], array('currency' => $subscription_details['currency'], 'ex_tax_label' => $subscription_details['display_excluding_tax_label']));
    } else {
        $initial_amount_string = $subscription_details['initial_amount'];
    }
    if (is_numeric($subscription_details['recurring_amount'])) {
        $recurring_amount_string = wc_price($subscription_details['recurring_amount'], array('currency' => $subscription_details['currency'], 'ex_tax_label' => $subscription_details['display_excluding_tax_label']));
    } else {
        $recurring_amount_string = $subscription_details['recurring_amount'];
    }
    $subscription_period_string = wcs_get_subscription_period_strings($subscription_details['subscription_interval'], $subscription_details['subscription_period']);
    $subscription_ranges = wcs_get_subscription_ranges();
    if ($subscription_details['subscription_length'] > 0 && $subscription_details['subscription_length'] == $subscription_details['subscription_interval']) {
        if (!empty($subscription_details['initial_amount'])) {
            if ($subscription_details['subscription_interval'] == $subscription_details['subscription_length'] && 0 == $subscription_details['trial_length']) {
                $subscription_string = $initial_amount_string;
            } else {
                // translators: 1$: initial amount, 2$: initial description (e.g. "up front"), 3$: recurring amount string (e.g. "£10 / month" )
                $subscription_string = sprintf(__('%1$s %2$s then %3$s', 'woocommerce-subscriptions'), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string);
            }
        } else {
            $subscription_string = $recurring_amount_string;
        }
    } elseif (true === $subscription_details['is_synced'] && in_array($subscription_details['subscription_period'], array('week', 'month', 'year'))) {
        // Verbosity is important here to enable translation
        $payment_day = $subscription_details['synchronised_payment_day'];
        switch ($subscription_details['subscription_period']) {
            case 'week':
                $payment_day_of_week = WC_Subscriptions_Synchroniser::get_weekday($payment_day);
                if (1 == $subscription_details['subscription_interval']) {
                    if (!empty($subscription_details['initial_amount'])) {
                        // translators: 1$: initial amount, 2$: initial description (e.g. "up front"), 3$: recurring amount string, 4$: payment day of the week (e.g. "$15 up front, then $10 every Wednesday")
                        $subscription_string = sprintf(__('%1$s %2$s then %3$s every %4$s', 'woocommerce-subscriptions'), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string, $payment_day_of_week);
                    } else {
                        // translators: 1$: recurring amount string, 2$: day of the week (e.g. "$10 every Wednesday")
                        $subscription_string = sprintf(__('%1$s every %2$s', 'woocommerce-subscriptions'), $recurring_amount_string, $payment_day_of_week);
                    }
                } else {
                    // e.g. $5 every 2 weeks on Wednesday
                    if (!empty($subscription_details['initial_amount'])) {
                        // translators: 1$: initial amount, 2$: initial description (e.g. "up front" ), 3$: recurring amount, 4$: interval (e.g. "2nd week"), 5$: day of the week (e.g. "Thursday"); (e.g. "$10 up front, then $20 every 2nd week on Wednesday")
                        $subscription_string = sprintf(__('%1$s %2$s then %3$s every %4%s on %5$s', 'woocommerce-subscriptions'), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string, wcs_get_subscription_period_strings($subscription_details['subscription_interval'], $subscription_details['subscription_period']), $payment_day_of_week);
                    } else {
                        // translators: 1$: recurring amount string, 2$: interval (e.g. "2nd week"), 3$: day of the week (e.g. "Thursday"); (e.g. "$10 every 2nd week on Wednesday")
                        $subscription_string = sprintf(__('%1$s every %2$s on %3$s', 'woocommerce-subscriptions'), $recurring_amount_string, wcs_get_subscription_period_strings($subscription_details['subscription_interval'], $subscription_details['subscription_period']), $payment_day_of_week);
                    }
                }
                break;
            case 'month':
                if (1 == $subscription_details['subscription_interval']) {
                    // e.g. $15 on the 15th of each month
                    if (!empty($subscription_details['initial_amount'])) {
                        if ($payment_day > 27) {
                            // translators: 1$: initial amount, 2$: initial description (e.g. "up front"), 3$: recurring amount; (e.g. "$10 up front then $30 on the last day of each month")
                            $subscription_string = sprintf(__('%1$s %2$s then %3$s on the last day of each month', 'woocommerce-subscriptions'), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string);
                        } else {
                            // translators: 1$: initial amount, 2$: initial description (e.g. "up front"), 3$: recurring amount, 4$: day of the month (e.g. "23rd"); (e.g. "$10 up front then $40 on the 23rd of each month")
                            $subscription_string = sprintf(__('%1$s %2$s then %3$s on the %4$s of each month', 'woocommerce-subscriptions'), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string, WC_Subscriptions::append_numeral_suffix($payment_day));
                        }
                    } else {
                        if ($payment_day > 27) {
                            // translators: placeholder is recurring amount
                            $subscription_string = sprintf(__('%s on the last day of each month', 'woocommerce-subscriptions'), $recurring_amount_string);
                        } else {
                            // translators: 1$: recurring amount, 2$: day of the month (e.g. "23rd")
                            $subscription_string = sprintf(__('%1$s on the %2$s of each month', 'woocommerce-subscriptions'), $recurring_amount_string, WC_Subscriptions::append_numeral_suffix($payment_day));
                        }
                    }
                } else {
                    // e.g. $15 on the 15th of every 3rd month
                    if (!empty($subscription_details['initial_amount'])) {
                        if ($payment_day > 27) {
                            // translators: 1$: initial amount, 2$: initial description (e.g. "up front"), 3$: recurring amount, 4$: interval (e.g. "3rd")
                            $subscription_string = sprintf(__('%1$s %2$s then %3$s on the last day of every %4$s month', 'woocommerce-subscriptions'), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string, WC_Subscriptions::append_numeral_suffix($subscription_details['subscription_interval']));
                        } else {
                            // translators: 1$: initial amount, 2$: initial description (e.g. "up front"), 3$: recurring amount, 4$: day of the month (e.g. "23rd"), 5$: interval (e.g. "3rd")
                            $subscription_string = sprintf(__('%1$s %2$s then %3$s on the %4$s day of every %5$s month', 'woocommerce-subscriptions'), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string, WC_Subscriptions::append_numeral_suffix($payment_day), WC_Subscriptions::append_numeral_suffix($subscription_details['subscription_interval']));
                        }
                    } else {
//.........这里部分代码省略.........
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:101,代码来源:wcs-formatting-functions.php


示例10: maybe_change_users_subscription

 /**
  * Checks if the current request is by a user to change the status of their subscription, and if it is
  * validate the subscription cancellation request and maybe processes the cancellation. 
  *
  * @since 1.0
  */
 public static function maybe_change_users_subscription()
 {
     global $woocommerce;
     if (isset($_GET['change_subscription_to']) && isset($_GET['subscription_key']) && isset($_GET['_wpnonce'])) {
         $user_id = get_current_user_id();
         $subscription = self::get_subscription($_GET['subscription_key']);
         if (wp_verify_nonce($_GET['_wpnonce'], $_GET['subscription_key']) === false) {
             WC_Subscriptions::add_notice(sprintf(__('That subscription can not be changed to %s. Please contact us if you need assistance.', 'woocommerce-subscriptions'), $_GET['change_subscription_to']), 'error');
         } elseif (empty($subscription)) {
             WC_Subscriptions::add_notice(__('That doesn\'t appear to be one of your subscriptions.', 'woocommerce-subscriptions'), 'error');
         } elseif (!WC_Subscriptions_Manager::can_subscription_be_changed_to($_GET['change_subscription_to'], $_GET['subscription_key'], $user_id)) {
             WC_Subscriptions::add_notice(sprintf(__('That subscription can not be changed to %s. Please contact us if you need assistance.', 'woocommerce-subscriptions'), $_GET['change_subscription_to']), 'error');
         } elseif (!in_array($_GET['change_subscription_to'], array('active', 'on-hold', 'cancelled'))) {
             WC_Subscriptions::add_notice(sprintf(__('Unknown subscription status: "%s". Please contact us if you need assistance.', 'woocommerce-subscriptions'), $_GET['change_subscription_to']), 'error');
         } else {
             switch ($_GET['change_subscription_to']) {
                 case 'active':
                     if (WC_Subscriptions_Manager::subscription_requires_payment($_GET['subscription_key'], $user_id)) {
                         WC_Subscriptions::add_notice(sprintf(__('You can not reactive that subscription until paying to renew it. Please contact us if you need assistance.', 'woocommerce-subscriptions'), $_GET['change_subscription_to']), 'error');
                     } else {
                         self::reactivate_subscription($user_id, $_GET['subscription_key']);
                         $status_message = __('reactivated', 'woocommerce-subscriptions');
                     }
                     break;
                 case 'on-hold':
                     if (self::current_user_can_suspend_subscription($_GET['subscription_key'])) {
                         self::put_subscription_on_hold($user_id, $_GET['subscription_key']);
                         $status_message = __('suspended', 'woocommerce-subscriptions');
                     } else {
                         WC_Subscriptions::add_notice(sprintf(__('You can not suspend that subscription - the suspension limit has been reached. Please contact us if you need assistance.', 'woocommerce-subscriptions'), $_GET['change_subscription_to']), 'error');
                     }
                     break;
                 case 'cancelled':
                     self::cancel_subscription($user_id, $_GET['subscription_key']);
                     $status_message = __('cancelled', 'woocommerce-subscriptions');
                     break;
             }
             if (isset($status_message)) {
                 $order = new WC_Order($subscription['order_id']);
                 $order->add_order_note(sprintf(__('The status of subscription %s was changed to %s by the subscriber from their account page.', 'woocommerce-subscriptions'), $_GET['subscription_key'], $_GET['change_subscription_to']));
                 WC_Subscriptions::add_notice(sprintf(__('Your subscription has been %s.', 'woocommerce-subscriptions'), $status_message), 'success');
             }
         }
         wp_safe_redirect(get_permalink(woocommerce_get_page_id('myaccount')));
         exit;
     }
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:53,代码来源:class-wc-subscriptions-manager.php


示例11: prepare_items

 /**
  * Get, sort and filter subscriptions for display.
  *
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  * @since 1.0
  */
 function prepare_items()
 {
     global $wcs_list_table_statuses;
     $screen = get_current_screen();
     $per_page = $this->get_items_per_page($screen->get_option('per_page', 'option'), 10);
     $paged = isset($_GET['paged']) ? $_GET['paged'] : 1;
     $this->get_column_info();
     $status_to_show = isset($_GET['status']) ? $_GET['status'] : 'all';
     if (isset($_REQUEST['s']) || !empty($_REQUEST['orderby']) && 'next_payment_date' === $_REQUEST['orderby']) {
         @set_time_limit(300);
         $subscriptions = $wcs_list_table_statuses = array();
         // It's a search
         if (isset($_REQUEST['s'])) {
             $subscriptions_grouped_by_user = WC_Subscriptions_Manager::search_subscriptions($_REQUEST['s']);
         } else {
             // Order by next payment date
             $subscriptions_grouped_by_user = WC_Subscriptions_Manager::get_all_users_subscriptions();
         }
         foreach ($subscriptions_grouped_by_user as $user_id => $users_subscriptions) {
             // Filter by a certain customer?
             if (isset($_GET['_customer_user']) && (int) $user_id !== (int) $_GET['_customer_user']) {
                 continue;
             }
             foreach ($users_subscriptions as $subscription_key => $subscription) {
                 // Filter by a certain product?
                 if (isset($_GET['_product_id']) && (int) $subscription['product_id'] !== (int) $_GET['_product_id']) {
                     continue;
                 }
                 $wcs_list_table_statuses[$subscription['status']] = isset($wcs_list_table_statuses[$subscription['status']]) ? $wcs_list_table_statuses[$subscription['status']] + 1 : 1;
                 if ($status_to_show == $subscription['status'] || $status_to_show == 'all' && $subscription['status'] != 'trash') {
                     $subscriptions[$subscription_key] = $subscription + array('user_id' => $user_id, 'subscription_key' => $subscription_key);
                 }
             }
         }
         // If we have a request for a status that does not exist, default to all subscriptions
         if (!isset($wcs_list_table_statuses[$status_to_show])) {
             if ($status_to_show != 'all') {
                 $status_to_show = $_GET['status'] = 'all';
                 foreach ($subscriptions_grouped_by_user as $user_id => $users_subscriptions) {
                     // Filter by a certain customer?
                     if (isset($_GET['_customer_user']) && (int) $user_id !== (int) $_GET['_customer_user']) {
                         continue;
                     }
                     foreach ($users_subscriptions as $subscription_key => $subscription) {
                         // Filter by a certain product?
                         if (isset($_GET['_product_id']) && (int) $subscription['product_id'] !== (int) $_GET['_product_id']) {
                             continue;
                         }
                         $subscriptions[$subscription_key] = $subscription + array('user_id' => $user_id, 'subscription_key' => $subscription_key);
                     }
                 }
             } else {
                 $_GET['status'] = 'all';
             }
         }
         ksort($wcs_list_table_statuses);
         $wcs_list_table_statuses = array('all' => array_sum($wcs_list_table_statuses)) + $wcs_list_table_statuses;
         if (isset($wcs_list_table_statuses['trash'])) {
             $wcs_list_table_statuses['all'] = $wcs_list_table_statuses['all'] - $wcs_list_table_statuses['trash'];
         }
         $total_items = count($subscriptions);
         @usort($subscriptions, array(&$this, 'sort_subscriptions'));
         // Need to suppress warnings due to PHP bug here: https://bugs.php.net/bug.php?id=50688
         $subscriptions = array_slice($subscriptions, ($paged - 1) * $per_page, $per_page);
     } else {
         $subscriptions_query = array('paged' => $paged, 'subscriptions_per_page' => $per_page, 'subscription_status' => $status_to_show, 'order' => !empty($_REQUEST['order']) ? strtoupper($_REQUEST['order']) : 'DESC', 'orderby' => !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : '_subscription_start_date');
         // Filter by a certain customer?
         if (isset($_GET['_customer_user']) && !empty($_GET['_customer_user'])) {
             $subscriptions_query['customer_id'] = $_GET['_customer_user'];
         }
         // Filter by a certain product?
         if (isset($_GET['_product_id']) && !empty($_GET['_product_id'])) {
             $subscriptions_query['product_id'] = $_GET['_product_id'];
         }
         $subscriptions = WC_Subscriptions::get_subscriptions($subscriptions_query);
         $wcs_list_table_statuses = WC_Subscriptions::get_subscription_status_counts();
         if (isset($wcs_list_table_statuses['trash'])) {
             $wcs_list_table_statuses['all'] = $wcs_list_table_statuses['all'] - $wcs_list_table_statuses['trash'];
         }
         if ('all' === $status_to_show && !isset($subscriptions_query['customer_id']) && !isset($subscriptions_query['product_id'])) {
             $total_items = $wcs_list_table_statuses['all'];
         } else {
             $total_items = WC_Subscriptions::get_subscription_count($subscriptions_query);
         }
     }
     // Add sorted & sliced data to the items property to be used by the rest of the class
     $this->items = $subscriptions;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:100,代码来源:class-wc-subscriptions-list-table.php


示例12: recurring_order_totals_meta_box_section

    /**
     * Display recurring order totals on the "Edit Order" page.
     *
     * @param int $post_id The post ID of the shop_order post object.
     * @since 1.2.4
     * @return void
     */
    public static function recurring_order_totals_meta_box_section($post_id)
    {
        global $woocommerce, $wpdb, $current_screen;
        $order = new WC_Order($post_id);
        $display_none = ' style="display: none"';
        $contains_subscription = self::order_contains_subscription($order) ? true : false;
        $chosen_gateway = WC_Subscriptions_Payment_Gateways::get_payment_gateway(get_post_meta($post_id, '_recurring_payment_method', true));
        $manual_renewal = self::requires_manual_renewal($post_id);
        $changes_supported = $chosen_gateway === false || $manual_renewal == 'true' || $chosen_gateway->supports('subscription_amount_changes') ? 'true' : 'false';
        $data = get_post_meta($post_id);
        if (WC_Subscriptions::is_woocommerce_pre('2.2')) {
            ?>
	<div class="clear"></div>
</div>
		<?php 
        }
        ?>
<div id="gateway_support"<?php 
        if (!$contains_subscription) {
            echo $display_none;
        }
        ?>
>
	<input type="hidden" name="gateway_supports_subscription_changes" value="<?php 
        echo $changes_supported;
        ?>
">
	<div class="error"<?php 
        if (!$contains_subscription || $changes_supported == 'true') {
            echo $display_none;
        }
        ?>
>
		<p><?php 
        printf(__('The %s payment gateway is used to charge automatic subscription payments for this order. This gateway <strong>does not</strong> support changing a subscription\'s details.', 'woocommerce-subscriptions'), get_post_meta($post_id, '_recurring_payment_method_title', true));
        ?>
</p>
		<p>
			<?php 
        _e('It is strongly recommended you <strong>do not change</strong> any of the recurring totals or subscription item\'s details.', 'woocommerce-subscriptions');
        ?>
			<a href="http://docs.woothemes.com/document/subscriptions/add-or-modify-a-subscription/#section-4"><?php 
        _e('Learn More', 'woocommerce-subscriptions');
        ?>
 &raquo;</a>
		</p>
	</div>
</div>
<div id="recurring_order_totals"<?php 
        if (!$contains_subscription) {
            echo $display_none;
        }
        ?>
>
	<?php 
        if (WC_Subscriptions::is_woocommerce_pre('2.2')) {
            ?>
	<h3><?php 
            _e('Recurring Totals', 'woocommerce-subscriptions');
            ?>
</h3>
	<?php 
        }
        ?>

	<?php 
        if ('add' !== $current_screen->action) {
            // Can't add recurring shipping to a manually added subscription
            ?>
	<div class="totals_group">
		<h4><span class="tax_total_display inline_total"></span><?php 
            _e('Shipping for Renewal Orders', 'woocommerce-subscriptions');
            ?>
</h4>
		<div id="recurring_shipping_rows">
		<?php 
            if (!WC_Subscriptions::is_woocommerce_pre('2.1')) {
                if ($woocommerce->shipping()) {
                    $shipping_methods = $woocommerce->shipping->load_shipping_methods();
                }
                foreach (self::get_recurring_shipping_methods($order) as $item_id => $item) {
                    $chosen_method = $item['method_id'];
                    $shipping_title = $item['name'];
                    $shipping_cost = $item['cost'];
                    include plugin_dir_path(WC_Subscriptions::$plugin_file) . 'templates/admin/post-types/writepanels/order-shipping-html.php';
                }
                // Shipping created pre 2.1
                if (isset($data['_recurring_shipping_method'])) {
                    $item_id = 'old';
                    // so that when saving, we know to delete the data in the old form
                    $chosen_method = !empty($data['_recurring_shipping_method'][0]) ? $data['_recurring_shipping_method'][0] : '';
                    $shipping_title = !empty($data['_recurring_shipping_method_title'][0]) ? $data['_recurring_shipping_method_title'][0] : '';
                    $shipping_cost = !empty($data['_order_recurring_shipping_total'][0]) ? $data['_order_recurring_shipping_total'][0] : '0.00';
//.........这里部分代码省略.........
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:101,代码来源:class-wc-subscriptions-order.php


示例13: apply_subscription_discount

 /**
  * Apply sign up fee or recurring fee discount
  *
  * @since 1.2
  */
 public static function apply_subscription_discount($original_price, $cart_item, $cart)
 {
     _deprecated_function(__METHOD__, '2.0.10', 'Have moved to filtering on "woocommerce_coupon_get_discount_amount" to return discount amount. See: ' . __CLASS__ . '::get_discount_amount()');
     $product_id = $cart_item['data']->is_type(array('subscription_variation')) ? $cart_item['data']->variation_id : $cart_item['data']->id;
     if (!WC_Subscriptions_Product::is_subscription($product_id)) {
         return $original_price;
     }
     $price = $calculation_price = $original_price;
     $calculation_type = WC_Subscriptions_Cart::get_calculation_type();
     if (!empty($cart->applied_coupons)) {
         foreach ($cart->applied_coupons as $code) {
             $coupon = new WC_Coupon($code);
             // Pre 2.5 is_valid_for_product() does not use wc_get_product_coupon_types()
             if (WC_Subscriptions::is_woocommerce_pre('2.5')) {
                 $is_valid_for_product = true;
             } else {
                 $is_valid_for_product = $coupon->is_valid_for_product(wc_get_product($product_id), $cart_item);
             }
             if ($coupon->apply_before_tax() && $coupon->is_valid() && $is_valid_for_product) {
                 $apply_recurring_coupon = $apply_recurring_percent_coupon = $apply_initial_coupon = $apply_initial_percent_coupon = false;
                 // Apply recurring fee discounts to recurring total calculations
                 if ('recurring_total' == $calculation_type) {
                     $apply_recurring_coupon = 'recurring_fee' == $coupon->type ? true : false;
                     $apply_recurring_percent_coupon = 'recurring_percent' == $coupon->type ? true : false;
                 }
                 if ('none' == $calculation_type) {
                     // If all items have a free trial we don't need to apply recurring coupons to the initial total
                     if (!WC_Subscriptions_Cart::all_cart_items_have_free_trial()) {
                         if ('recurring_fee' == $coupon->type) {
                             $apply_initial_coupon = true;
                         }
                         if ('recurring_percent' == $coupon->type) {
                             $apply_initial_percent_coupon = true;
                         }
                     }
                     // Apply sign-up discounts to initial total
                     if (!empty($cart_item['data']->subscription_sign_up_fee)) {
                         if ('sign_up_fee' == $coupon->type) {
                             $apply_initial_coupon = true;
                         }
                         if ('sign_up_fee_percent' == $coupon->type) {
                             $apply_initial_percent_coupon = true;
                         }
                         $calculation_price = $cart_item['data']->subscription_sign_up_fee;
                     }
                 }
                 if ($apply_recurring_coupon || $apply_initial_coupon) {
                     $discount_amount = $calculation_price < $coupon->amount ? $calculation_price : $coupon->amount;
                     // Recurring coupons only apply when there is no free trial (carts can have a mix of free trial and non free trial items)
                     if ($apply_initial_coupon && 'recurring_fee' == $coupon->type && !empty($cart_item['data']->subscription_trial_length)) {
                         $discount_amount = 0;
                     }
                     $cart->discount_cart = $cart->discount_cart + $discount_amount * $cart_item['quantity'];
                     $cart = self::increase_coupon_discount_amount($cart, $coupon->code, $discount_amount * $cart_item['quantity']);
                     $price = $price - $discount_amount;
                 } elseif ($apply_recurring_percent_coupon) {
                     $discount_amount = round($calculation_price / 100 * $coupon->amount, WC()->cart->dp);
                     $cart->discount_cart = $cart->discount_cart + $discount_amount * $cart_item['quantity'];
                     $cart = self::increase_coupon_discount_amount($cart, $coupon->code, $discount_amount * $cart_item['quantity']);
                     $price = $price - $discount_amount;
                 } elseif ($apply_initial_percent_coupon) {
                     // Recurring coupons only apply when there is no free trial (carts can have a mix of free trial and non free trial items)
                     if ('recurring_percent' == $coupon->type && empty($cart_item['data']->subscription_trial_length)) {
                         $amount_to_discount = $cart_item['data']->subscription_price;
                     } else {
                         $amount_to_discount = 0;
                     }
                     // Sign up fee coupons only apply to sign up fees
                     if ('sign_up_fee_percent' == $coupon->type) {
                         $amount_to_discount = $cart_item['data']->subscription_sign_up_fee;
                     }
                     $discount_amount = round($amount_to_discount / 100 * $coupon->amount, WC()->cart->dp);
                     $cart->discount_cart = $cart->discount_cart + $discount_amount * $cart_item['quantity'];
                     $cart = self::increase_coupon_discount_amount($cart, $coupon->code, $discount_a 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WC_Subscriptions_Manager类代码示例发布时间:2022-05-23
下一篇:
PHP WC_Shortcodes类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap