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


PHP WC_Subscriptions_Order::get_outstanding_balance方法代码示例

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


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

示例1: gateway_scheduled_subscription_payment

 /**
  * For versions of WooCommerce prior to the existence of the woocommerce_available_gateways, 
  * hide available gateways with JavaScript.
  * 
  * @since 1.0
  */
 public static function gateway_scheduled_subscription_payment($user_id, $subscription_key)
 {
     $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key);
     $order = new WC_Order($subscription['order_id']);
     $amount_to_charge = WC_Subscriptions_Order::get_price_per_period($order, $subscription['product_id']);
     $outstanding_payments = WC_Subscriptions_Order::get_outstanding_balance($order, $subscription['product_id']);
     if ($outstanding_payments > 0) {
         $amount_to_charge += $outstanding_payments;
     }
     do_action('scheduled_subscription_payment_' . $order->payment_method, $amount_to_charge, $order, $subscription['product_id']);
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:17,代码来源:class-wc-subscriptions-payment-gateways.php

示例2: gateway_scheduled_subscription_payment

 /**
  * Fire a gateway specific hook for when a subscription payment is due.
  *
  * @since 1.0
  */
 public static function gateway_scheduled_subscription_payment($user_id, $subscription_key)
 {
     $subscription = WC_Subscriptions_Manager::get_subscription($subscription_key);
     $order = new WC_Order($subscription['order_id']);
     if (!WC_Subscriptions_Order::requires_manual_renewal($order)) {
         $amount_to_charge = WC_Subscriptions_Order::get_recurring_total($order);
         $outstanding_payments = WC_Subscriptions_Order::get_outstanding_balance($order, $subscription['product_id']);
         if ('yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_add_outstanding_balance', 'no') && $outstanding_payments > 0) {
             $amount_to_charge += $outstanding_payments;
         }
         do_action('scheduled_subscription_payment_' . $order->recurring_payment_method, $amount_to_charge, $order, $subscription['product_id']);
     }
 }
开发者ID:bulats,项目名称:chef,代码行数:18,代码来源:class-wc-subscriptions-payment-gateways.php

示例3: generate_renewal_order


//.........这里部分代码省略.........
                 if ($checkout_object->posted['shiptobilling']) {
                     if (isset($checkout_object->posted[str_replace('shipping_', 'billing_', $key)])) {
                         $postvalue = $checkout_object->posted[str_replace('shipping_', 'billing_', $key)];
                         update_post_meta($renewal_order_id, '_' . $key, $postvalue);
                         update_post_meta($original_order->id, '_' . $key, $postvalue);
                     }
                 } else {
                     $postvalue = $checkout_object->posted[$key];
                     update_post_meta($renewal_order_id, '_' . $key, $postvalue);
                     update_post_meta($original_order->id, '_' . $key, $postvalue);
                 }
                 // User
                 if ($postvalue && $customer_id) {
                     update_user_meta($customer_id, $key, $postvalue);
                 }
             }
         }
     }
     $order_meta_query = "SELECT `meta_key`, `meta_value`\n\t\t\t\t\t\t\t FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\t WHERE `post_id` = {$original_order->id}\n\t\t\t\t\t\t\t AND `meta_key` NOT IN ('_paid_date', '_completed_date', '_order_key', '_edit_lock', '_original_order')";
     // Superseding existing order so don't carry over payment details
     if ('parent' == $args['new_order_role'] || true === $args['checkout_renewal']) {
         $order_meta_query .= " AND `meta_key` NOT IN ('_payment_method', '_payment_method_title', '_recurring_payment_method', '_recurring_payment_method_title', '_shipping_method', '_shipping_method_title', '_recurring_shipping_method', '_recurring_shipping_method_title')";
     } else {
         $order_meta_query .= " AND `meta_key` NOT LIKE '_order_recurring_%' AND `meta_key` NOT IN ('_payment_method', '_payment_method_title', '_recurring_payment_method', '_recurring_payment_method_title', '_shipping_method', '_shipping_method_title', '_recurring_shipping_method', '_recurring_shipping_method_title')";
     }
     // Allow extensions to add/remove order meta
     $order_meta_query = apply_filters('woocommerce_subscriptions_renewal_order_meta_query', $order_meta_query, $original_order->id, $renewal_order_id, $args['new_order_role']);
     // Carry all the required meta from the old order over to the new order
     $order_meta = $wpdb->get_results($order_meta_query, 'ARRAY_A');
     $order_meta = apply_filters('woocommerce_subscriptions_renewal_order_meta', $order_meta, $original_order->id, $renewal_order_id, $args['new_order_role']);
     foreach ($order_meta as $meta_item) {
         add_post_meta($renewal_order_id, $meta_item['meta_key'], maybe_unserialize($meta_item['meta_value']), true);
     }
     $outstanding_balance = WC_Subscriptions_Order::get_outstanding_balance($original_order, $product_id);
     if (true === $args['checkout_renewal']) {
         $failed_payment_multiplier = 1;
         update_post_meta($renewal_order_id, '_order_shipping', woocommerce_format_total($woocommerce->cart->shipping_total));
         update_post_meta($renewal_order_id, '_order_discount', woocommerce_format_total($woocommerce->cart->get_order_discount_total()));
         update_post_meta($renewal_order_id, '_cart_discount', woocommerce_format_total($woocommerce->cart->get_cart_discount_total()));
         update_post_meta($renewal_order_id, '_order_tax', woocommerce_format_total($woocommerce->cart->tax_total));
         update_post_meta($renewal_order_id, '_order_shipping_tax', woocommerce_format_total($woocommerce->cart->shipping_tax_total));
         update_post_meta($renewal_order_id, '_order_total', woocommerce_format_total($woocommerce->cart->total));
         update_post_meta($renewal_order_id, '_checkout_renewal', 'yes');
     } else {
         // If there are outstanding payment amounts, add them to the order, otherwise set the order details to the values of the recurring totals
         if ($outstanding_balance > 0 && 'yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_add_outstanding_balance', 'no')) {
             $failed_payment_multiplier = WC_Subscriptions_Order::get_failed_payment_count($original_order, $product_id);
         } else {
             $failed_payment_multiplier = 1;
         }
         // Set order totals based on recurring totals from the original order
         $cart_discount = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_discount_cart', true);
         $order_discount = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_discount_total', true);
         $order_shipping_tax = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_shipping_tax_total', true);
         $order_shipping = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_shipping_total', true);
         $order_tax = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_tax_total', true);
         $order_total = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_total', true);
         update_post_meta($renewal_order_id, '_cart_discount', $cart_discount);
         update_post_meta($renewal_order_id, '_order_discount', $order_discount);
         update_post_meta($renewal_order_id, '_order_shipping_tax', $order_shipping_tax);
         update_post_meta($renewal_order_id, '_order_shipping', $order_shipping);
         update_post_meta($renewal_order_id, '_order_tax', $order_tax);
         update_post_meta($renewal_order_id, '_order_total', $order_total);
         update_post_meta($renewal_order_id, '_shipping_method', $original_order->recurring_shipping_method);
         update_post_meta($renewal_order_id, '_shipping_method_title', $original_order->recurring_shipping_method_title);
         // Apply the recurring shipping & payment methods to child renewal orders
开发者ID:bulats,项目名称:chef,代码行数:67,代码来源:class-wc-subscriptions-renewal-order.php

示例4: generate_renewal_order

 /**
  * Creates a new order for renewing a subscription product based on the details of a previous order.
  *
  * No trial periods or sign up fees are applied to the renewal order. However, if the order has failed
  * payments and the store manager has set failed payments to be added to renewal orders, then the
  * orders totals will be set to include the outstanding balance.
  *
  * If the $new_order_role flag is set to 'parent', then the renewal order will supersede the existing 
  * order. The existing order and subscription associated with it will be cancelled. A new order and
  * subscription will be created. 
  *
  * If the $new_order_role flag is 'child', the $original_order will remain the master order for the
  * subscription and the new order is just for accepting a recurring payment on the subscription.
  *
  * Renewal orders have the same meta data as the original order. If the renewal order is set to be a 'child'
  * then any subscription related meta data will not be stored on the new order. This is to keep subscription
  * meta data associated only with the one master order for the subscription.
  *
  * @param $order WC_Order | int The WC_Order object or ID of the order for which the a new order should be created.
  * @param $product_id string The ID of the subscription product in the order which needs to be added to the new order.
  * @param $new_order_role string A flag to indicate whether the new order should become the master order for the subscription. Accepts either 'parent' or 'child'. Defaults to 'parent' - replace the existing order.
  * @since 1.2
  */
 public static function generate_renewal_order($original_order, $product_id, $new_order_role = 'parent')
 {
     global $wpdb;
     if (!is_object($original_order)) {
         $original_order = new WC_Order($original_order);
     }
     if (!WC_Subscriptions_Order::order_contains_subscription($original_order) || !WC_Subscriptions_Order::is_item_a_subscription($original_order, $product_id)) {
         return false;
     }
     if (self::is_renewal($original_order, 'child')) {
         $original_order = self::get_parent_order($original_order);
     }
     $renewal_order_key = uniqid('order_');
     // Create the new order
     $renewal_order_data = array('post_type' => 'shop_order', 'post_title' => sprintf(__('Subscription Renewal Order – %s', WC_Subscriptions::$text_domain), strftime(_x('%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', WC_Subscriptions::$text_domain))), 'post_status' => 'publish', 'ping_status' => 'closed', 'post_excerpt' => $original_order->customer_note, 'post_author' => 1, 'post_password' => $renewal_order_key);
     if ('child' == $new_order_role) {
         $renewal_order_data['post_parent'] = $original_order->id;
     }
     $renewal_order_id = wp_insert_post($renewal_order_data);
     // Set the order as pending
     wp_set_object_terms($renewal_order_id, 'pending', 'shop_order_status');
     // Set a unique key for this order
     update_post_meta($renewal_order_id, '_order_key', $renewal_order_key);
     $order_meta_query = "SELECT `meta_key`, `meta_value` FROM {$wpdb->postmeta} WHERE `post_id` = {$original_order->id} AND `meta_key` NOT IN ('_paid_date', '_completed_date', '_order_key', '_edit_lock', '_original_order')";
     // Superseding existing order so don't carry over payment details
     if ('parent' == $new_order_role) {
         $order_meta_query .= " AND `meta_key` NOT IN ('_payment_method', '_payment_method_title')";
     } else {
         $order_meta_query .= " AND `meta_key` NOT LIKE '_order_recurring_%'";
     }
     // Allow extensions to add/remove order meta
     $order_meta_query = apply_filters('woocommerce_subscriptions_renewal_order_meta_query', $order_meta_query, $original_order->id, $renewal_order_id, $new_order_role);
     // Carry all the required meta from the old order over to the new order
     $order_meta = $wpdb->get_results($order_meta_query, 'ARRAY_A');
     $order_meta = apply_filters('woocommerce_subscriptions_renewal_order_meta', $order_meta, $original_order->id, $renewal_order_id, $new_order_role);
     foreach ($order_meta as $meta_item) {
         add_post_meta($renewal_order_id, $meta_item['meta_key'], maybe_unserialize($meta_item['meta_value']), true);
     }
     $outstanding_balance = WC_Subscriptions_Order::get_outstanding_balance($original_order, $product_id);
     // If there are outstanding payment amounts, add them to the order, otherwise set the order details to the values of the recurring totals
     if ($outstanding_balance > 0 && 'yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_add_outstanding_balance')) {
         $failed_payment_multiplier = WC_Subscriptions_Order::get_failed_payment_count($original_order, $product_id);
     } else {
         $failed_payment_multiplier = 1;
     }
     // Set order totals based on recurring totals from the original order
     $cart_discount = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_discount_cart', true);
     $order_discount = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_discount_total', true);
     $order_shipping_tax = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_shipping_tax_total', true);
     $order_tax = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_tax_total', true);
     $order_total = $failed_payment_multiplier * get_post_meta($original_order->id, '_order_recurring_total', true);
     update_post_meta($renewal_order_id, '_cart_discount', $cart_discount);
     update_post_meta($renewal_order_id, '_order_discount', $order_discount);
     update_post_meta($renewal_order_id, '_order_shipping_tax', $order_shipping_tax);
     update_post_meta($renewal_order_id, '_order_tax', $order_tax);
     update_post_meta($renewal_order_id, '_order_total', $order_total);
     // Set order taxes based on recurring taxes from the original order
     $recurring_order_taxes = get_post_meta($original_order->id, '_order_recurring_taxes', true);
     foreach ($recurring_order_taxes as $index => $recurring_order_tax) {
         if (isset($recurring_order_tax['cart_tax']) && $recurring_order_tax['cart_tax'] > 0) {
             $recurring_order_taxes[$index]['cart_tax'] = $failed_payment_multiplier * $recurring_order_tax['cart_tax'];
         } else {
             $recurring_order_taxes[$index]['cart_tax'] = 0;
         }
         if (isset($recurring_order_tax['shipping_tax']) && $recurring_order_tax['shipping_tax'] > 0) {
             $recurring_order_taxes[$index]['shipping_tax'] = $failed_payment_multiplier * $recurring_order_tax['shipping_tax'];
         } else {
             $recurring_order_taxes[$index]['shipping_tax'] = 0;
         }
     }
     update_post_meta($renewal_order_id, '_order_taxes', $recurring_order_taxes);
     // Set line totals to be recurring line totals and remove the subscription/recurring related item meta from each order item
     $order_items = WC_Subscriptions_Order::get_recurring_items($original_order);
     // Allow extensions to add/remove items or item meta
     $order_items = apply_filters('woocommerce_subscriptions_renewal_order_items', $order_items, $original_order->id, $renewal_order_id, $product_id, $new_order_role);
     foreach ($order_items as $item_index => $order_item) {
         $item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
//.........这里部分代码省略.........
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:101,代码来源:class-wc-subscriptions-renewal-order.php

示例5: generate_renewal_order


//.........这里部分代码省略.........
                 $renewal_order_data['ID'] = $renewal_order_id;
                 wp_update_post($renewal_order_data);
                 // Clear the old line items - we'll add these again in case they changed
                 $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d )", $renewal_order_id));
                 $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d", $renewal_order_id));
             }
         }
     }
     if ($create_new_order) {
         $renewal_order_id = wp_insert_post($renewal_order_data);
     }
     if (WC_Subscriptions::is_woocommerce_pre_2_2()) {
         // WC 2.1 order status
         // Set the order as pending
         wp_set_object_terms($renewal_order_id, 'pending', 'shop_order_status');
     }
     // Set a unique key for this order
     update_post_meta($renewal_order_id, '_order_key', $renewal_order_key);
     $order_meta_query = "SELECT `meta_key`, `meta_value`\n\t\t\t\t\t\t\t FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\t WHERE `post_id` = {$original_order->id}\n\t\t\t\t\t\t\t AND `meta_key` NOT IN ('_paid_date', '_completed_date', '_order_key', '_edit_lock', '_original_order', '_wc_points_earned', '_transaction_id')";
     // Superseding existing order so don't carry over payment details
     if ('parent' == $args['new_order_role'] || true === $args['checkout_renewal']) {
         $order_meta_query .= " AND `meta_key` NOT IN ('_payment_method', '_payment_method_title', '_recurring_payment_method', '_recurring_payment_method_title', '_shipping_method', '_shipping_method_title', '_recurring_shipping_method', '_recurring_shipping_method_title')";
     } else {
         $order_meta_query .= " AND `meta_key` NOT LIKE '_order_recurring_%' AND `meta_key` NOT IN ('_payment_method', '_payment_method_title', '_recurring_payment_method', '_recurring_payment_method_title', '_shipping_method', '_shipping_method_title', '_recurring_shipping_method', '_recurring_shipping_method_title')";
     }
     // Allow extensions to add/remove order meta
     $order_meta_query = apply_filters('woocommerce_subscriptions_renewal_order_meta_query', $order_meta_query, $original_order->id, $renewal_order_id, $args['new_order_role']);
     // Carry all the required meta from the old order over to the new order
     $order_meta = $wpdb->get_results($order_meta_query, 'ARRAY_A');
     $order_meta = apply_filters('woocommerce_subscriptions_renewal_order_meta', $order_meta, $original_order->id, $renewal_order_id, $args['new_order_role']);
     foreach ($order_meta as $meta_item) {
         add_post_meta($renewal_order_id, $meta_item['meta_key'], maybe_unserialize($meta_item['meta_value']), true);
     }
     $outstanding_balance = WC_Subscriptions_Order::get_outstanding_balance($original_order, $product_id);
     $failed_payment_multiplier = 1;
     if (false == $args['checkout_renewal']) {
         // If there are outstanding payment amounts, add them to the order, otherwise set the order details to the values of the recurring totals
         if ($outstanding_balance > 0 && 'yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_add_outstanding_balance', 'no')) {
             $failed_payment_multiplier = WC_Subscriptions_Order::get_failed_payment_count($original_order, $product_id);
         }
         // Set order totals based on recurring totals from the original order
         $cart_discount = $failed_payment_multiplier * wc_format_decimal(get_post_meta($original_order->id, '_order_recurring_discount_cart', true));
         $order_discount = $failed_payment_multiplier * wc_format_decimal(get_post_meta($original_order->id, '_order_recurring_discount_total', true));
         $order_shipping_tax = $failed_payment_multiplier * wc_format_decimal(get_post_meta($original_order->id, '_order_recurring_shipping_tax_total', true));
         $order_shipping = $failed_payment_multiplier * wc_format_decimal(get_post_meta($original_order->id, '_order_recurring_shipping_total', true));
         $order_tax = $failed_payment_multiplier * wc_format_decimal(get_post_meta($original_order->id, '_order_recurring_tax_total', true));
         $order_total = $failed_payment_multiplier * wc_format_decimal(get_post_meta($original_order->id, '_order_recurring_total', true));
         update_post_meta($renewal_order_id, '_cart_discount', $cart_discount);
         update_post_meta($renewal_order_id, '_order_discount', $order_discount);
         update_post_meta($renewal_order_id, '_order_shipping_tax', $order_shipping_tax);
         update_post_meta($renewal_order_id, '_order_shipping', $order_shipping);
         update_post_meta($renewal_order_id, '_order_tax', $order_tax);
         update_post_meta($renewal_order_id, '_order_total', $order_total);
         // Set shipping for orders created with WC 2.0.n (or when we are using WC 2.0.n)
         if (WC_Subscriptions::is_woocommerce_pre_2_1() || isset($original_order->recurring_shipping_method)) {
             update_post_meta($renewal_order_id, '_shipping_method', $original_order->recurring_shipping_method);
             update_post_meta($renewal_order_id, '_shipping_method_title', $original_order->recurring_shipping_method_title);
             // Also set recurring shipping as it's a parent renewal order
             if ('parent' == $args['new_order_role']) {
                 update_post_meta($renewal_order_id, '_recurring_shipping_method', $original_order->recurring_shipping_method);
                 update_post_meta($renewal_order_id, '_recurring_shipping_method_title', $original_order->recurring_shipping_method_title);
             }
         }
         // Apply the recurring shipping & payment methods to child renewal orders
         if ('child' == $args['new_order_role']) {
             update_post_meta($renewal_order_id, '_payment_method', $original_order->recurring_payment_method);
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:67,代码来源:class-wc-subscriptions-renewal-order.php

示例6: gateway_scheduled_subscription_payment

 /**
  * Fire a gateway specific hook for when a subscription payment is due.
  *
  * @since 1.0
  */
 public static function gateway_scheduled_subscription_payment($user_id, $subscription_key)
 {
     $subscription = WC_Subscriptions_Manager::get_subscription($subscription_key);
     $order = new WC_Order($subscription['order_id']);
     if (!WC_Subscriptions_Order::requires_manual_renewal($order)) {
         $amount_to_charge = WC_Subscriptions_Order::get_recurring_total($order);
         $outstanding_payments = WC_Subscriptions_Order::get_outstanding_balance($order, $subscription['product_id']);
         if ('yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_add_outstanding_balance', 'no') && $outstanding_payments > 0) {
             $amount_to_charge += $outstanding_payments;
         }
         if ($amount_to_charge > 0) {
             $transaction_id = get_post_meta($order->id, '_transaction_id', true);
             update_post_meta($order->id, '_transaction_id_original', $transaction_id);
             delete_post_meta($order->id, '_transaction_id', $transaction_id);
             // just in case the gateway uses add_post_meta() not update_post_meta() - this will be set later based on `'_transaction_id_original'` regardless of whether the payment fails or succeeds
             do_action('scheduled_subscription_payment_' . $order->recurring_payment_method, $amount_to_charge, $order, $subscription['product_id']);
         }
     }
 }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:24,代码来源:class-wc-subscriptions-payment-gateways.php


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