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


PHP WC_Subscriptions_Manager::get_users_subscriptions方法代码示例

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


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

示例1: add_subscription_args

 public function add_subscription_args($args, $offer_id, $action)
 {
     if (empty($args) || $action == 'skip') {
         return $args;
     }
     $so_offers = new SO_Offers();
     $user_details = $so_offers->get_user_details();
     $user_has_bought = !empty($user_details['offer_rule_has_bought']) ? explode(',', $user_details['offer_rule_has_bought']) : array();
     $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions();
     $preserve_keys = true;
     $subscriptions = array_reverse($subscriptions, $preserve_keys);
     foreach ($subscriptions as $subscription_key => $subscription) {
         if (in_array($subscription['product_id'], $user_has_bought) && 'active' == $subscription['status']) {
             $args['switch-subscription'] = $subscription_key;
             $args['auto-switch'] = 'true';
             break;
         }
     }
     return $args;
 }
开发者ID:WP-Panda,项目名称:allergenics,代码行数:20,代码来源:class-so-subscription.php

示例2: upd_mem_plan

/** Update Member Plan **/
function upd_mem_plan()
{
    global $current_user, $woocommerce, $wpdb;
    $mess = array();
    $mess['act'] = 'success';
    parse_str($_POST['form_data'], $d);
    get_currentuserinfo();
    $product_id = $d['meal_plan_type'];
    $arr = array();
    $cur_user_subscription = WC_Subscriptions_Manager::get_users_subscriptions(get_current_user_id());
    /* $current_subscription To Cancel all users previous subscription */
    foreach ($cur_user_subscription as $suk => $suv) {
        $orderID = $suv['order_id'];
        $suv['product_id'] = $d['meal_plan'];
        $arr[$suv['order_id'] . '_' . $d['meal_plan']] = $suv;
        update_user_meta(get_current_user_id(), 'wp_woocommerce_subscriptions', $arr);
        break;
    }
    // Create Order (send cart variable so we can record items and reduce inventory). Only create if this is a new order, not if the payment was rejected.
    $product_id = $d['meal_plan_type'];
    $_product = new WC_Product($product_id);
    // Set values
    $item = array();
    // Add line item
    $srOW = $wpdb->get_row("select * FROM wp_woocommerce_order_items WHERE order_id = " . $orderID);
    $item_id = $srOW->order_item_id;
    $args = array('post_type' => 'product', 'post_status' => 'publish');
    $loop = new WP_Query($args);
    $i = 0;
    if ($loop->have_posts()) {
        while ($loop->have_posts()) {
            $loop->the_post();
            $____product = get_product(get_the_ID());
            $_var[get_the_ID()] = $____product->get_available_variations();
        }
    }
    wp_reset_query();
    foreach ($_var as $_k => $_variations) {
        foreach ($_variations as $_vk => $_vv) {
            if ($_vv['variation_id'] == $product_id) {
                $variation_name = $_vv['attributes']['attribute_servings'];
                $p = strip_tags($_vv['price_html']);
            }
        }
    }
    // update post meta for pricing
    update_post_meta($orderID, '_order_total', get_post_meta($product_id, '_price', true));
    update_post_meta($orderID, '_order_recurring_total', get_post_meta($product_id, '_subscription_price', true));
    // Add subscription details so order state persists even when a product is changed
    $period = WC_Subscriptions_Product::get_period($product_id);
    $interval = WC_Subscriptions_Product::get_interval($product_id);
    $length = WC_Subscriptions_Product::get_length($product_id);
    $trial_length = WC_Subscriptions_Product::get_trial_length($product_id);
    $trial_period = WC_Subscriptions_Product::get_trial_period($product_id);
    $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product_id);
    woocommerce_update_order_item_meta($item_id, '_qty', 1);
    woocommerce_update_order_item_meta($item_id, '_tax_class', '');
    woocommerce_update_order_item_meta($item_id, '_product_id', $d['meal_plan']);
    woocommerce_update_order_item_meta($item_id, '_variation_id', $product_id);
    woocommerce_update_order_item_meta($item_id, '_line_subtotal', get_post_meta($product_id, '_price', true));
    woocommerce_update_order_item_meta($item_id, '_line_total', get_post_meta($product_id, '_subscription_price', true));
    // WC_Subscriptions_Product::get_price() would return a price without filters applied
    woocommerce_update_order_item_meta($item_id, '_line_tax', 0);
    woocommerce_update_order_item_meta($item_id, '_line_subtotal_tax', 0);
    // WC_Subscriptions_Product::get_price() would return a price without filters applied
    woocommerce_update_order_item_meta($item_id, 'Servings:', $variation_name);
    woocommerce_update_order_item_meta($item_id, '_subscription_period', $period);
    woocommerce_update_order_item_meta($item_id, '_subscription_interval', $interval);
    woocommerce_update_order_item_meta($item_id, '_subscription_length', $length);
    woocommerce_update_order_item_meta($item_id, '_subscription_trial_length', $trial_length);
    woocommerce_update_order_item_meta($item_id, '_subscription_trial_period', $trial_period);
    woocommerce_update_order_item_meta($item_id, '_subscription_recurring_amount', get_post_meta($product_id, '_subscription_price', true));
    // WC_Subscriptions_Product::get_price() would return a price without filters applied
    woocommerce_update_order_item_meta($item_id, '_subscription_sign_up_fee', $sign_up_fee);
    // Calculated recurring amounts for the item
    woocommerce_update_order_item_meta($item_id, '_recurring_line_total', number_format((double) get_post_meta($product_id, '_price', true), 2, '.', ''));
    woocommerce_update_order_item_meta($item_id, '_recurring_line_tax', '');
    woocommerce_update_order_item_meta($item_id, '_recurring_line_subtotal', number_format((double) get_post_meta($product_id, '_regular_price', true), 2, '.', ''));
    woocommerce_update_order_item_meta($item_id, '_recurring_line_subtotal_tax', '');
    $odr = $orderID;
    /* Fetch Oder Details */
    //if(($_vv['variation_id'] ==  $vari_ID))
    $mealOrder = woocommerce_get_order_item_meta($srOW->order_item_id, 'Servings:', true);
    $mealType = woocommerce_get_order_item_meta($srOW->order_item_id, '_subscription_period', true);
    $mealTotal = woocommerce_get_order_item_meta($srOW->order_item_id, '_recurring_line_subtotal', true);
    $vari_ID = woocommerce_get_order_item_meta($srOW->order_item_id, '_variation_id', true);
    $_product = get_product($product_id);
    $srOW = $wpdb->get_row("UPDATE wp_woocommerce_order_items SET order_item_name = '" . $_product->post->post_title . "' WHERE order_item_id=" . $item_id);
    $html = '<div class="info_heading">Meal Plan</div>
                <div class="info_values">
                    <p>' . $_product->post->post_title . '</p>
                </div>
                <div class="info_heading">Subscriptions Type</div>
                <div class="info_values">
                    <p>' . $variation_name . '</p>
                </div>
                <div class="info_heading">Price</div>
                <div class="info_values">
                    <p>' . $p . '</p>
//.........这里部分代码省略.........
开发者ID:bulats,项目名称:chef,代码行数:101,代码来源:functions.php

示例3: pre_process_shop_order_meta


//.........这里部分代码省略.........
         }
     } else {
         // WC 1.x
         if (!isset($_POST['_order_recurring_taxes'])) {
             $_POST['_order_recurring_taxes'] = array();
         }
         foreach ($_POST['_order_recurring_taxes'] as $index => $tax_details) {
             if (!isset($tax_details['compound'])) {
                 $_POST['_order_recurring_taxes'][$index]['compound'] = 0;
             }
         }
         update_post_meta($post_id, '_order_recurring_taxes', $_POST['_order_recurring_taxes']);
     }
     // Check if all the subscription products on the order have associated subscriptions on the user's account, and if not, add a new one
     foreach ($product_ids as $order_item_id => $product_id) {
         $is_existing_item = false;
         if (in_array($product_id, $existing_product_ids)) {
             $is_existing_item = true;
         }
         // If this is a new item and it's not a subscription product, ignore it
         if (!$is_existing_item && !WC_Subscriptions_Product::is_subscription($product_id)) {
             continue;
         }
         // If this is an existing item and it's not a subscription, ignore it
         if ($is_existing_item && !WC_Subscriptions_Order::is_item_subscription($order, $product_id)) {
             continue;
         }
         $subscription_key = WC_Subscriptions_Manager::get_subscription_key($post_id, $product_id);
         $subscription = array();
         // If order customer changed, move the subscription from the old customer's account to the new customer
         if (!empty($order->customer_user) && $order->customer_user != (int) $_POST['customer_user']) {
             $subscription = WC_Subscriptions_Manager::remove_users_subscription($order->customer_user, $subscription_key);
             if (!empty($subscription)) {
                 $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions((int) $_POST['customer_user']);
                 $subscriptions[$subscription_key] = $subscription;
                 WC_Subscriptions_Manager::update_users_subscriptions((int) $_POST['customer_user'], $subscriptions);
             }
         }
         // In case it's a new order or the customer has changed
         $order->customer_user = $order->user_id = (int) $_POST['customer_user'];
         $subscription = WC_Subscriptions_Manager::get_users_subscription($order->customer_user, $subscription_key);
         if (empty($subscription)) {
             // Add a new subscription
             // The order may not exist yet, so we need to set a few things ourselves
             if (empty($order->order_key)) {
                 $order->order_key = uniqid('order_');
                 add_post_meta($post_id, '_order_key', $order->order_key, true);
             }
             if (empty($_POST['order_date'])) {
                 $start_date = gmdate('Y-m-d H:i:s');
             } else {
                 $start_date = get_gmt_from_date($_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00');
             }
             WC_Subscriptions_Manager::create_pending_subscription_for_order($order, $product_id, array('start_date' => $start_date));
             // Add the subscription meta for this item to the order
             $functions_and_meta = array('get_period' => '_order_subscription_periods', 'get_interval' => '_order_subscription_intervals', 'get_length' => '_order_subscription_lengths');
             foreach ($functions_and_meta as $function_name => $meta_key) {
                 $subscription_meta = self::get_meta($order, $meta_key, array());
                 $subscription_meta[$product_id] = WC_Subscriptions_Product::$function_name($product_id);
                 update_post_meta($order->id, $meta_key, $subscription_meta);
             }
             // This works because process_shop_order_item_meta saves item meta to workaround a WC 1.x bug and in WC 2.0+ meta is added when the item is added via Ajax
             self::process_shop_order_item_meta($post_id, $post);
             // If the order's existing status is something other than pending and the order status is not being changed, manually set the subscription's status (otherwise, it will be handled when WC transitions the order's status)
             if ($order->status == $_POST['order_status'] && 'pending' != $order->status) {
                 switch ($order->status) {
开发者ID:bulats,项目名称:chef,代码行数:67,代码来源:class-wc-subscriptions-order.php

示例4: maybe_activate_woocommerce_subscriptions

 public static function maybe_activate_woocommerce_subscriptions()
 {
     global $wpdb;
     $is_active = get_option(WC_Subscriptions_Admin::$option_prefix . '_is_active', false);
     $active_version = get_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '0');
     if ($is_active == false || version_compare($active_version, self::$version, '<')) {
         // Update meta keys for 1.1 to 1.1.1 multisite changes
         if (version_compare($active_version, '1.1.1', '<')) {
             $updated_count = $wpdb->update($wpdb->usermeta, array('meta_key' => $wpdb->get_blog_prefix() . WC_Subscriptions_Manager::$users_meta_key), array('meta_key' => WC_Subscriptions_Manager::$users_meta_key));
         }
         // Fix any products that were incorrectly added as a subscription for a user in 1.1.2
         if (version_compare($active_version, '1.1.3', '<')) {
             foreach (get_users() as $user) {
                 $users_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($user->ID);
                 foreach ($users_subscriptions as $subscription_key => $subscription_details) {
                     if (!isset($subscription_details['order_id'])) {
                         WC_Subscriptions_Manager::remove_users_subscription($user->ID, $subscription_key);
                     }
                 }
             }
         }
         // Add the "Subscriptions" product type if it doesn't exist
         if (!get_term_by('slug', sanitize_title(self::$name), 'product_type')) {
             wp_insert_term(self::$name, 'product_type');
         }
         // If no Subscription settings exist, add defaults
         if (get_option(WC_Subscriptions_Admin::$option_prefix . '_cancelled_role', false) == false) {
             WC_Subscriptions_Admin::add_default_settings();
         }
         add_option(WC_Subscriptions_Admin::$option_prefix . '_is_active', true);
         update_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', self::$version);
         set_transient(self::$activation_transient, true, 60 * 60);
         do_action('woocommerce_subscriptions_activated');
     }
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:35,代码来源:woocommerce-subscriptions.php

示例5: subscription_switch_handler

 /**
  * Handles the subscription upgrade/downgrade process.
  *
  * @since 1.4
  */
 public static function subscription_switch_handler()
 {
     global $woocommerce, $post;
     // If the current user doesn't own the subscription, remove the query arg from the URL
     if (isset($_GET['switch-subscription'])) {
         // Visiting a switch link for someone elses subscription
         if (!WC_Subscriptions_Manager::user_owns_subscription($_GET['switch-subscription'])) {
             wp_redirect(remove_query_arg('switch-subscription'));
             exit;
         } else {
             if (isset($_GET['auto-switch'])) {
                 $switch_message = __('You have a subscription to this product. Choosing a new subscription will replace your existing subscription.', 'woocommerce-subscriptions');
             } else {
                 $switch_message = __('Choose a new subscription.', 'woocommerce-subscriptions');
             }
             WC_Subscriptions::add_notice($switch_message, 'notice');
         }
     } elseif ((is_cart() || is_checkout()) && !is_order_received_page() && false !== ($cart_item = self::cart_contains_subscription_switch())) {
         if (!WC_Subscriptions_Manager::user_owns_subscription($cart_item['subscription_key'])) {
             WC_Subscriptions::add_notice(__('Your cart contained an invalid subscription switch request and has been emptied.', 'woocommerce-subscriptions'), 'error');
             $woocommerce->cart->empty_cart(true);
             wp_redirect($woocommerce->cart->get_cart_url());
             exit;
         } else {
             WC_Subscriptions::add_notice(__('Once sign up is complete, this will replace your existing subscription.', 'woocommerce-subscriptions'), 'notice');
         }
     } elseif (is_product() && ($product = get_product($post))) {
         // Automatically initiate the switch process for limited variable subscriptions
         if (($product->is_type(array('variable-subscription', 'subscription_variation', 'grouped')) || 0 !== $product->post->post_parent) && 'no' != $product->limit_subscriptions) {
             // Check if the user has an active subscription for this product, and if so, initiate the switch process
             $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions();
             $subscriptions = array_reverse($subscriptions);
             $children = $product->get_children();
             foreach ($subscriptions as $subscription_key => $subscription) {
                 $is_grouped = $product->is_type('grouped') && in_array($subscription['product_id'], $children) ? true : false;
                 if ($subscription['product_id'] == $product->id || $is_grouped) {
                     // For grouped products, we need to check the child products limitations, not the grouped product's (which will have no limitation)
                     if ($is_grouped) {
                         $child_product = get_product($subscription['product_id']);
                         $limitation = $child_product->limit_subscriptions;
                     } else {
                         $limitation = $product->limit_subscriptions;
                     }
                     // If the product is limited
                     if ('any' == $limitation || $limitation == $subscription['status'] || 'active' == $limitation && 'on-hold' == $subscription['status']) {
                         // If switching is enabled for this product type, initiate the auto-switch process
                         if (self::is_product_of_switchable_type($product)) {
                             wp_redirect(add_query_arg('auto-switch', 'true', self::get_switch_link($subscription_key)));
                             exit;
                         } else {
                             WC_Subscriptions::add_notice(__('You have already subscribed to this product and it is limited to one per customer. You can not purchase the product again.', 'woocommerce-subscriptions'), 'notice');
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:64,代码来源:class-wc-subscriptions-switcher.php

示例6: delete_payment_method

 /**
  * Delete a stored billing method
  */
 function delete_payment_method($payment_method)
 {
     global $woocommerce;
     $user = wp_get_current_user();
     $customer_vault_ids = get_user_meta($user->ID, 'customer_vault_ids', true);
     $id = $customer_vault_ids[$payment_method];
     // If method is Single Billing, actually delete the record
     if (substr($id, 0, 1) !== '_') {
         $inspire_request = array('username' => $this->username, 'password' => $this->password, 'customer_vault' => 'delete_customer', 'customer_vault_id' => $id);
         $response = $this->post_and_get_response($inspire_request);
         if ($response['response'] != 1) {
             $woocommerce->add_error(__('Sorry, there was an error: ', 'woocommerce') . $response['responsetext']);
             $woocommerce->show_messages();
             return;
         }
     }
     $last_method = count($customer_vault_ids) - 1;
     // Update subscription references
     if (class_exists('WC_Subscriptions_Manager')) {
         foreach ((array) WC_Subscriptions_Manager::get_users_subscriptions($user->ID) as $subscription) {
             $subscription_payment_method = get_post_meta($subscription['order_id'], 'payment_method_number', true);
             // Cancel subscriptions that were purchased with the deleted method
             if ($subscription_payment_method == $payment_method) {
                 delete_post_meta($subscription['order_id'], 'payment_method_number');
                 WC_Subscriptions_Manager::cancel_subscription($user->ID, WC_Subscriptions_Manager::get_subscription_key($subscription['order_id']));
             } else {
                 if ($subscription_payment_method == $last_method && $subscription['status'] != 'cancelled') {
                     update_post_meta($subscription['order_id'], 'payment_method_number', $payment_method);
                 }
             }
         }
     }
     // Delete the reference by replacing it with the last method in the array
     if ($payment_method < $last_method) {
         $customer_vault_ids[$payment_method] = $customer_vault_ids[$last_method];
     }
     unset($customer_vault_ids[$last_method]);
     update_user_meta($user->ID, 'customer_vault_ids', $customer_vault_ids);
     $woocommerce->add_message(__('Successfully deleted your information!', 'woocommerce'));
     $woocommerce->show_messages();
 }
开发者ID:shubham79,项目名称:Jhintaak,代码行数:44,代码来源:gateway-inspire.php

示例7: validate_package

 /**
  * Validate package
  * @param  int $package_id
  * @param  bool $is_user_package
  * @return bool|WP_Error
  */
 private static function validate_package($package_id, $is_user_package)
 {
     if (empty($package_id)) {
         return new WP_Error('error', __('Invalid Package', 'wp-job-manager-wc-paid-listings'));
     } elseif ($is_user_package) {
         if (!wc_paid_listings_package_is_valid(get_current_user_id(), $package_id)) {
             return new WP_Error('error', __('Invalid Package', 'wp-job-manager-wc-paid-listings'));
         }
     } else {
         $package = wc_get_product($package_id);
         if (!$package->is_type('job_package') && !$package->is_type('job_package_subscription')) {
             return new WP_Error('error', __('Invalid Package', 'wp-job-manager-wc-paid-listings'));
         }
         // Don't let them buy the same subscription twice if the subscription is for the package
         if (class_exists('WC_Subscriptions') && is_user_logged_in() && $package->is_type('job_package_subscription') && 'package' === $package->package_subscription_type) {
             $user_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions(get_current_user_id());
             foreach ($user_subscriptions as $user_subscription) {
                 if ($user_subscription['product_id'] == $package_id) {
                     return new WP_Error('error', __('You already have this subscription.', 'wp-job-manager-wc-paid-listings'));
                 }
             }
         }
     }
     return true;
 }
开发者ID:sabdev1,项目名称:sabstaff,代码行数:31,代码来源:class-wc-paid-listings-submit-job-form.php

示例8: upgrade_to_version_1_1_3

 /**
  * A bug in 1.1.2 was adding products to a users account as a subscription. This fixes that.
  *
  * @since 1.2
  */
 private static function upgrade_to_version_1_1_3()
 {
     foreach (get_users() as $user) {
         $users_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($user->ID);
         foreach ($users_subscriptions as $subscription_key => $subscription_details) {
             if (!isset($subscription_details['order_id'])) {
                 WC_Subscriptions_Manager::remove_users_subscription($user->ID, $subscription_key);
             }
         }
     }
 }
开发者ID:bulats,项目名称:chef,代码行数:16,代码来源:class-wc-subscriptions-upgrader.php

示例9: get_users_renewal_link_for_product

 /**
  * Returns a URL including required parameters for an authenticated user to renew a subscription by product ID.
  *
  * @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
  * @since 1.2
  */
 public static function get_users_renewal_link_for_product($product_id)
 {
     $renewal_url = '';
     if (is_user_logged_in()) {
         $users_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions();
         foreach ($users_subscriptions as $subscription_key => $users_subscription) {
             if ($users_subscription['product_id'] == $product_id && self::can_subscription_be_renewed($subscription_key)) {
                 $renewal_url = self::get_users_renewal_link($subscription_key);
                 break;
             }
         }
     }
     return $renewal_url;
 }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:20,代码来源:class-wc-subscriptions-renewal-order.php

示例10: blendercloud_api

function blendercloud_api($atts)
{
    $user_data = array('shop_id' => '0', 'cloud_access' => 0, 'expiration_date' => '1970-01-01 00:00:00');
    $last_expiration_date = new DateTime('1970-01-01 00:00:00');
    // map blenderid to userid
    $args = array('search' => $_GET['blenderid'], 'search_columns' => array('user_login'));
    $user_query = new WP_User_Query($args);
    // Get the results from the query, returning the first user
    $users = $user_query->get_results();
    if (!empty($users)) {
        $user_id = $users[0]->ID;
        $user_data['shop_id'] = $user_id;
        // process simple products (prepaid subscriptions)
        $order_ids = bo_get_all_user_orders($user_id, 'completed');
        foreach ($order_ids as $order_id) {
            $order = new WC_Order($order_id);
            $order_date = $order->order_date;
            $items = $order->get_items();
            foreach ($items as $item) {
                $tmp = bo_empty_subscription_line();
                $product_id = $item['product_id'];
                $product = get_product($product_id);
                $sku = $product->get_sku();
                $expiry_date = new DateTime($order_date);
                $tmp['sku'] = $sku;
                switch ($sku) {
                    case 'cloud-prepaid-3':
                    case 'cloud-prepaid-3-renewal':
                        $expiry_date->modify('+3 month');
                        break;
                    case 'cloud-prepaid-18':
                        $expiry_date->modify('+18 month');
                        break;
                    default:
                        continue 2;
                        // skip to next product
                }
                $tmp['expiration_date'] = $expiry_date->format('Y-m-d H:i:s');
                $tmp['subscription_status'] = 'prepaid';
                $now = new DateTime("now");
                if ($expiry_date > $now) {
                    $tmp['cloud_access'] = 1;
                }
                if ($expiry_date > $last_expiration_date) {
                    $last_expiration_date = $expiry_date;
                }
                $user_data['subscriptions'][] = $tmp;
            }
        }
        // process recurring subscriptions
        $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($user_id);
        if (!empty($subscriptions)) {
            // iterate over all subscriptions.
            foreach ($subscriptions as $subscription_details) {
                if ($subscription_details['status'] != 'trash') {
                    $order_id = $subscription_details['order_id'];
                    $product_id = $subscription_details['product_id'];
                    $order = new WC_Order($order_id);
                    // print_r($order);
                    // $next_payment_date	= WC_Subscriptions_Manager::get_next_payment_date( $subscription_key, $user_id, 'mysql' );
                    $subscription_key = WC_Subscriptions_Manager::get_subscription_key($order_id, $product_id);
                    if ($subscription_details['expiry_date'] == 0 && !in_array($subscription_details['status'], array('cancelled', 'switched'))) {
                        $end_time = WC_Subscriptions_Manager::get_next_payment_date($subscription_key, $user_id, 'mysql');
                        $end_timestamp = strtotime($end_time);
                    } else {
                        if (in_array($subscription_details['status'], array('cancelled', 'switched'))) {
                            $end_of_prepaid_term = wc_next_scheduled_action('scheduled_subscription_end_of_prepaid_term', array('user_id' => (int) $user_id, 'subscription_key' => $subscription_key));
                            if (false === $end_of_prepaid_term) {
                                $end_timestamp = strtotime($subscription_details['end_date']);
                            } else {
                                $end_timestamp = $end_of_prepaid_term;
                            }
                        } else {
                            $end_timestamp = strtotime($subscription_details['expiry_date']);
                        }
                    }
                    //					if( $users[0]->data->user_email == 'perepausancho@gmail.com' ) {
                    //						print_r($subscription_details);
                    //					}
                    if ($subscription_details['status'] == 'cancelled') {
                        $end_timestamp = strtotime($subscription_details['trial_expiry_date']);
                    }
                    if ($subscription_details['status'] == 'on-hold') {
                        $end_timestamp = strtotime($subscription_details['last_payment_date']);
                    }
                    $end_time = date("Y-m-d H:i:s", $end_timestamp);
                    $product = get_product($product_id);
                    $sku = $product->get_sku();
                    $tmp = bo_empty_subscription_line();
                    $tmp['expiration_date'] = $end_time;
                    $tmp['subscription_status'] = $subscription_details['status'];
                    $expiry_date = new DateTime($end_time);
                    if ($expiry_date > $last_expiration_date) {
                        $last_expiration_date = $expiry_date;
                    }
                    $now = new DateTime("now");
                    $tmp['cloud_access'] = $expiry_date > $now ? 1 : 0;
                    $tmp['sku'] = $sku;
                    // if order is refunded, stop access
                    if ($order->status == 'refunded') {
//.........这里部分代码省略.........
开发者ID:keshvenderg,项目名称:cloudshop,代码行数:101,代码来源:api.php

示例11: user_column_values

 /**
  * Hooked to the users table to display a check mark if a given user has an active subscription.
  * 
  * @param string $value The string to output in the column specified with $column_name
  * @param string $column_name The string key for the current column in an admin table
  * @param int $user_id The ID of the user to which this row relates
  * @return string $value A check mark if the column is the active_subscriber column and the user has an active subscription.
  * @since 1.0
  */
 public static function user_column_values($value, $column_name, $user_id)
 {
     global $woocommerce;
     if ($column_name == 'woocommerce_active_subscriber') {
         $users_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($user_id);
         // Inactive until proven otherwise
         $value = '<img src="' . $woocommerce->plugin_url() . '/assets/images/success-off.png" alt="no" />';
         if (!empty($users_subscriptions)) {
             foreach ($users_subscriptions as $subscription) {
                 if ($subscription['status'] == 'active') {
                     $value = '<img src="' . $woocommerce->plugin_url() . '/assets/images/success.png" alt="yes" />';
                     break;
                 }
             }
         }
     }
     return $value;
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:27,代码来源:class-wc-subscriptions-admin.php

示例12: maybe_update_subscription_order_addresses

 public function maybe_update_subscription_order_addresses($user_id, $load_address)
 {
     global $woocommerce, $wp;
     if (!WC_Subscriptions_Manager::user_has_subscription($user_id)) {
         return;
     }
     if ($load_address != 'shipping') {
         return;
     }
     $subscription_ids = array();
     if (isset($_POST['update_all_subscriptions_addresses'])) {
         $users_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($user_id);
         foreach ($users_subscriptions as $subscription) {
             array_push($subscription_ids, $subscription['order_id']);
         }
     } elseif (isset($_POST['update_subscription_address'])) {
         $subscription = WC_Subscriptions_Manager::get_subscription($_POST['update_subscription_address']);
         // Update the address only if the user actually owns the subscription
         if (!empty($subscription)) {
             array_push($subscription_ids, $subscription['order_id']);
         }
     }
     if (count($subscription_ids) > 0) {
         $base_order = $order = wc_get_order($subscription_ids[0]);
         $args = array('numberposts' => -1, 'post_type' => 'shop_order', 'post_status' => 'publish', 'tax_query' => array(array('taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array('processing'))), 'meta_query' => array(array('key' => '_customer_user', 'value' => $user_id), array('key' => '_original_order', 'value' => $subscription_ids)));
         $posts = get_posts($args);
         $address = array('first_name' => $base_order->shipping_first_name, 'last_name' => $base_order->shipping_last_name, 'address_1' => $base_order->shipping_address_1, 'address_2' => $base_order->shipping_address_2, 'city' => $base_order->shipping_city, 'state' => $base_order->shipping_state, 'postcode' => $base_order->shipping_postcode, 'country' => $base_order->shipping_country);
         foreach ($posts as $post) {
             $order = wc_get_order($post->ID);
             $order->set_address($address, 'shipping');
         }
     }
 }
开发者ID:whatthefork,项目名称:woocommerce-fedex-shipping-labels,代码行数:33,代码来源:woocommerce-fedex-shipping-labels.php

示例13: get_my_subscriptions_template

 /**
  * Loads the my-subscriptions.php template on the My Account page.
  *
  * @since 1.0
  */
 public static function get_my_subscriptions_template()
 {
     $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions();
     $user_id = get_current_user_id();
     $all_actions = array();
     foreach ($subscriptions as $subscription_key => $subscription_details) {
         $actions = array();
         if ($subscription_details['status'] == 'trash') {
             unset($subscriptions[$subscription_key]);
             continue;
         }
         $admin_with_suspension_disallowed = current_user_can('manage_woocommerce') && 0 == get_option(WC_Subscriptions_Admin::$option_prefix . '_max_customer_suspensions', 0) ? true : false;
         if (WC_Subscriptions_Manager::can_subscription_be_changed_to('on-hold', $subscription_key, $user_id) && WC_Subscriptions_Manager::current_user_can_suspend_subscription($subscription_key) && !$admin_with_suspension_disallowed) {
             $actions['suspend'] = array('url' => WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'on-hold'), 'name' => __('Suspend', 'woocommerce-subscriptions'));
         } elseif (WC_Subscriptions_Manager::can_subscription_be_changed_to('active', $subscription_key, $user_id) && !WC_Subscriptions_Manager::subscription_requires_payment($subscription_key, $user_id)) {
             $actions['reactivate'] = array('url' => WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'active'), 'name' => __('Reactivate', 'woocommerce-subscriptions'));
         }
         if (WC_Subscriptions_Renewal_Order::can_subscription_be_renewed($subscription_key, $user_id)) {
             $actions['renew'] = array('url' => WC_Subscriptions_Renewal_Order::get_users_renewal_link($subscription_key), 'name' => __('Renew', 'woocommerce-subscriptions'));
         }
         $renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders($subscription_details['order_id'], 'ID');
         $last_order_id = end($renewal_orders);
         if ($last_order_id) {
             $renewal_order = new WC_Order($last_order_id);
             if (WC_Subscriptions_Manager::can_subscription_be_changed_to('active', $subscription_key, $user_id) && in_array($renewal_order->status, array('pending', 'failed')) && !is_numeric(get_post_meta($renewal_order->id, '_failed_order_replaced_by', true))) {
                 $actions['pay'] = array('url' => $renewal_order->get_checkout_payment_url(), 'name' => __('Pay', 'woocommerce-subscriptions'));
             }
         } else {
             // Check if the master order still needs to be paid
             $order = new WC_Order($subscription_details['order_id']);
             if ('pending' == $order->status && WC_Subscriptions_Manager::can_subscription_be_changed_to('active', $subscription_key, $user_id)) {
                 $actions['pay'] = array('url' => $order->get_checkout_payment_url(), 'name' => __('Pay', 'woocommerce-subscriptions'));
             }
         }
         if (WC_Subscriptions_Manager::can_subscription_be_changed_to('cancelled', $subscription_key, $user_id) && $subscription_details['interval'] != $subscription_details['length']) {
             $actions['cancel'] = array('url' => WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'cancelled'), 'name' => __('Cancel', 'woocommerce-subscriptions'));
         }
         $all_actions[$subscription_key] = $actions;
     }
     $all_actions = apply_filters('woocommerce_my_account_my_subscriptions_actions', $all_actions, $subscriptions);
     woocommerce_get_template('myaccount/my-subscriptions.php', array('subscriptions' => $subscriptions, 'actions' => $all_actions, 'user_id' => $user_id), '', plugin_dir_path(__FILE__) . 'templates/');
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:47,代码来源:woocommerce-subscriptions.php

示例14: maybe_manually_change_subscriptions

 /**
  * When an order is added or updated from the admin interface, check if a new subscription product
  * has been manually added to the order, and if one has, create a new subscription. 
  * 
  * @param $post_id int The ID of the post which is the WC_Order object.
  * @param $post Object The post object of the order.
  * @since 1.1
  */
 public static function maybe_manually_change_subscriptions($post_id, $post)
 {
     $order = new WC_Order($post_id);
     // Check if all the subscription products on the order have associated subscriptions on the user's account, and if not, add a new one
     foreach ($_POST['item_id'] as $item_id) {
         if (!WC_Subscriptions_Product::is_subscription($item_id)) {
             continue;
         }
         $subscription_key = WC_Subscriptions_Manager::get_subscription_key($post_id, $item_id);
         $subscription = array();
         // If order customer changed, move the subscription from the old customer's account to the new customer
         if (!empty($order->customer_user) && $order->customer_user != (int) $_POST['customer_user']) {
             $subscription = WC_Subscriptions_Manager::remove_users_subscription($order->customer_user, $subscription_key);
             $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions((int) $_POST['customer_user']);
             if (!empty($subscription)) {
                 $subscriptions[$subscription_key] = $subscription;
                 WC_Subscriptions_Manager::update_users_subscriptions((int) $_POST['customer_user'], $subscriptions);
             }
         }
         // In case it's a new order or the customer has changed
         $order->customer_user = $order->user_id = (int) $_POST['customer_user'];
         $subscription = WC_Subscriptions_Manager::get_users_subscription($order->customer_user, $subscription_key);
         if (empty($subscription)) {
             // Add a new subscription
             // The order doesn't may not exist yet, so we need to set a few things ourselves
             $order->order_key = uniqid('order_');
             add_post_meta($post_id, '_order_key', $order->order_key, true);
             WC_Subscriptions_Manager::create_pending_subscription_for_order($order, $item_id);
             // Add the subscription meta for this item to the order
             $functions_and_meta = array('get_period' => '_order_subscription_periods', 'get_interval' => '_order_subscription_intervals', 'get_length' => '_order_subscription_lengths');
             foreach ($functions_and_meta as $function_name => $meta_key) {
                 $subscription_meta = self::get_meta($order, $meta_key, array());
                 $subscription_meta[$item_id] = WC_Subscriptions_Product::$function_name($item_id);
                 update_post_meta($order->id, $meta_key, $subscription_meta);
             }
             // Set the subscription's status if it should be something other than pending
             switch ($order->status) {
                 case 'completed':
                 case 'processing':
                     WC_Subscriptions_Manager::activate_subscription($order->customer_user, $subscription_key);
                     break;
                 case 'refunded':
                 case 'cancelled':
                     WC_Subscriptions_Manager::cancel_subscription($order->customer_user, $subscription_key);
                     break;
                 case 'failed':
                     WC_Subscriptions_Manager::failed_subscription_signup($order->customer_user, $subscription_key);
                     break;
             }
         }
     }
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:60,代码来源:class-wc-subscriptions-order.php

示例15: do_subscriptions_shortcode

    /**
     * Callback for the [subscriptions] shortcode that displays subscription names for a particular user.
     *
     * @param array $attributes Shortcode attributes.
     * @return string
     */
    public static function do_subscriptions_shortcode($attributes)
    {
        $attributes = wp_parse_args($attributes, array('user_id' => 0, 'status' => 'active'));
        $status = $attributes['status'];
        $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($attributes['user_id']);
        if (empty($subscriptions)) {
            return '<ul class="user-subscriptions no-user-subscriptions">
						<li>No subscriptions found.</li>
					</ul>';
        }
        $list = '<ul class="user-subscriptions">';
        foreach ($subscriptions as $subscription) {
            if ($subscription['status'] == $status || $status == 'all') {
                $list .= sprintf('<li>%s</li>', WC_Subscriptions_Order::get_item_name($subscription['order_id'], $subscription['product_id']));
            }
        }
        $list .= '</ul>';
        return $list;
    }
开发者ID:bulats,项目名称:chef,代码行数:25,代码来源:class-wc-subscriptions-admin.php


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