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


PHP WC_Subscriptions_Order::get_item_by_id方法代码示例

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


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

示例1: update_subscription

 /**
  * Takes a subscription key and array of subscription details and updates the users subscription details accordingly.
  *
  * @uses wp_parse_args To allow only part of a subscription's details to be updated, like status.
  * @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
  * @param array $new_subscription_details An array of arrays with a subscription key and corresponding 'detail' => 'value' pair. Can alter any of these details:
  *        'start_date'          The date the subscription was activated
  *        'expiry_date'         The date the subscription expires or expired, false if the subscription will never expire
  *        'failed_payments'     The date the subscription's trial expires or expired, false if the subscription has no trial period
  *        'end_date'            The date the subscription ended, false if the subscription has not yet ended
  *        'status'              Subscription status can be: cancelled, active, expired or failed
  *        'completed_payments'  An array of MySQL formatted dates for all payments that have been made on the subscription
  *        'failed_payments'     An integer representing a count of failed payments
  *        'suspension_count'    An integer representing a count of the number of times the subscription has been suspended for this billing period
  * @since 1.4
  */
 public static function update_subscription($subscription_key, $new_subscription_details)
 {
     $subscription = self::get_subscription($subscription_key);
     $item_id = WC_Subscriptions_Order::get_item_id_by_subscription_key($subscription_key);
     $item = WC_Subscriptions_Order::get_item_by_id($item_id);
     if (isset($new_subscription_details['status']) && 'deleted' == $new_subscription_details['status']) {
         woocommerce_delete_order_item($item_id);
     } else {
         $subscription_meta = array('start_date', 'expiry_date', 'trial_expiry_date', 'end_date', 'status', 'failed_payments', 'completed_payments', 'suspension_count');
         foreach ($subscription_meta as $meta_key) {
             if (isset($new_subscription_details[$meta_key]) && $new_subscription_details[$meta_key] != $subscription[$meta_key]) {
                 $subscription[$meta_key] = $new_subscription_details[$meta_key];
                 woocommerce_update_order_item_meta($item_id, '_subscription_' . $meta_key, $new_subscription_details[$meta_key]);
             }
         }
     }
     do_action('updated_users_subscription', $subscription_key, $new_subscription_details);
     return $subscription;
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:35,代码来源:class-wc-subscriptions-manager.php

示例2: maybe_add_switched_callback

 /**
  * Creates a 2.0 updated version of the "subscriptions_switched" callback for developers to hook onto.
  *
  * The subscription passed to the new `woocommerce_subscriptions_switched_item` callback is strictly the subscription
  * to which the `$new_order_item` belongs to; this may be a new or the original subscription.
  *
  * @since 2.0.5
  * @param WC_Order $order
  */
 public static function maybe_add_switched_callback($order)
 {
     if (wcs_order_contains_switch($order)) {
         $subscriptions = wcs_get_subscriptions_for_order($order);
         foreach ($subscriptions as $subscription) {
             foreach ($subscription->get_items() as $new_order_item) {
                 if (isset($new_order_item['switched_subscription_item_id'])) {
                     $product_id = wcs_get_canonical_product_id($new_order_item);
                     // we need to check if the switch order contains the line item that has just been switched so that we don't call the hook on items that were previously switched in another order
                     foreach ($order->get_items() as $order_item) {
                         if (wcs_get_canonical_product_id($order_item) == $product_id) {
                             do_action('woocommerce_subscriptions_switched_item', $subscription, $new_order_item, WC_Subscriptions_Order::get_item_by_id($new_order_item['switched_subscription_item_id']));
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:bself,项目名称:nuimage-wp,代码行数:29,代码来源:class-wc-subscriptions-switcher.php


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