Ejemplo n.º 1
0
 /**
  * Returns the string key for a subscription purchased in an order specified by $order_id
  * 
  * @param order_id int The ID of the order in which the subscription was purchased. 
  * @param product_id int The ID of the subscription product.
  * @return string The key representing the given subscription.
  * @since 1.0
  */
 public static function get_subscription_key($order_id, $product_id = '')
 {
     // If we have a child renewal order, we need the parent order's ID
     if (WC_Subscriptions_Renewal_Order::is_renewal($order_id, array('order_role' => 'child'))) {
         $order_id = WC_Subscriptions_Renewal_Order::get_parent_order_id($order_id);
     }
     if (empty($product_id)) {
         $order = new WC_Order($order_id);
         $order_items = WC_Subscriptions_Order::get_recurring_items($order);
         $first_order_item = reset($order_items);
         $product_id = WC_Subscriptions_Order::get_items_product_id($first_order_item);
     }
     $subscription_key = $order_id . '_' . $product_id;
     return apply_filters('woocommerce_subscription_key', $subscription_key, $order_id, $product_id);
 }
Ejemplo n.º 2
0
 /**
  * Outputs the contents of the "Renewal Orders" meta box.
  *
  * @param object $post Current post data.
  */
 public static function renewal_orders_meta_box($post)
 {
     $order = new WC_Order(absint($post->ID));
     if (WC_Subscriptions_Renewal_Order::is_renewal($order, array('order_role' => 'child'))) {
         $parent_id = WC_Subscriptions_Renewal_Order::get_parent_order_id($order);
     } else {
         if (WC_Subscriptions_Order::order_contains_subscription($order)) {
             $parent_id = $post->ID;
         }
     }
     //Find any renewal orders associated with this order.
     $items = get_posts(array('post_type' => $post->post_type, 'post_parent' => $parent_id, 'numberposts' => -1));
     if (WC_Subscriptions_Renewal_Order::is_renewal($order, array('order_role' => 'child'))) {
         $parent_order = new WC_Order($parent_id);
         printf('<p>%1$s <a href="%2$s">%3$s</a></p>', __('Initial Order:', WC_Subscriptions::$text_domain), get_edit_post_link($parent_id), $parent_order->get_order_number());
     }
     if (empty($items)) {
         printf(' <p class="renewal-subtitle">%s</p>', __('No renewal payments yet.', WC_Subscriptions::$text_domain));
     } else {
         printf('<p class="renewal-subtitle">%s</p>', __('Renewal Orders:', WC_Subscriptions::$text_domain));
         echo '<ul class="renewal-orders">';
         foreach ($items as $item) {
             $renewal_order = new WC_Order($item->ID);
             if ($item->ID == $post->ID) {
                 printf('<li><strong>%s</strong></li>', $renewal_order->get_order_number());
             } else {
                 printf('<li><a href="%1$s">%2$s</a></li>', get_edit_post_link($item->ID), $renewal_order->get_order_number());
             }
         }
         echo '</ul>';
     }
 }
 /**
  * Returns the string key for a subscription purchased in an order specified by $order_id
  * 
  * @param order_id int The ID of the order in which the subscription was purchased. 
  * @param product_id int The ID of the subscription product.
  * @return string The key representing the given subscription.
  * @since 1.0
  */
 public static function get_subscription_key($order_id, $product_id = '')
 {
     // If we have a child renewal order, we need the parent order's ID
     if (WC_Subscriptions_Renewal_Order::is_renewal($order_id, 'child')) {
         $order_id = WC_Subscriptions_Renewal_Order::get_parent_order_id($order_id);
     }
     if (empty($product_id)) {
         $order = new WC_Order($order_id);
         $order_items = $order->get_items();
         $product_id = $order_items[0]['id'];
     }
     $subscription_key = $order_id . '_' . $product_id;
     return apply_filters('woocommerce_subscription_key', $subscription_key, $order_id, $product_id);
 }
 /**
  * Returns the string key for a subscription purchased in an order specified by $order_id
  *
  * @param order_id int The ID of the order in which the subscription was purchased.
  * @param product_id int The ID of the subscription product.
  * @return string The key representing the given subscription.
  * @since 1.0
  */
 public static function get_subscription_key($order_id, $product_id = '')
 {
     _deprecated_function(__METHOD__, '2.0', 'wcs_get_old_subscription_key( WC_Subscription $subscription )');
     // If we have a child renewal order, we need the parent order's ID
     if (wcs_order_contains_renewal($order_id)) {
         $order_id = WC_Subscriptions_Renewal_Order::get_parent_order_id($order_id);
     }
     // Get the ID of the first order item in a subscription created by this order
     if (empty($product_id)) {
         $subscriptions = wcs_get_subscriptions_for_order($order_id, array('order_type' => 'parent'));
         foreach ($subscriptions as $subscription) {
             $subscription_items = $subscription->get_items();
             if (!empty($subscription_items)) {
                 break;
             }
         }
         if (!empty($subscription_items)) {
             $first_item = reset($subscription_items);
             $product_id = WC_Subscriptions_Order::get_items_product_id($first_item);
         } else {
             $product_id = '';
         }
     }
     $subscription_key = $order_id . '_' . $product_id;
     return apply_filters('woocommerce_subscription_key', $subscription_key, $order_id, $product_id);
 }