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

PHP WC_Subscriptions_Product类代码示例

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

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



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

示例1: is_subscription

 /**
  * Tells if a product is a subscription, provided that Subs is installed.
  *
  * @param  mixed    $product_id   product or id to check
  * @return boolean                true if Subs exists and product is a Sub
  */
 public function is_subscription($product_id)
 {
     if (!class_exists('WC_Subscriptions')) {
         return false;
     }
     return WC_Subscriptions_Product::is_subscription($product_id);
 }
开发者ID:alexbaron50,项目名称:Rockk3rs-Lab-Test,代码行数:13,代码来源:class-wc-pb-compatibility.php


示例2: apply_subscription_discount_before_tax

 /**
  * Apply sign up fee or recurring fee discount before tax is calculated
  *
  *
  * @since 1.2
  */
 public static function apply_subscription_discount_before_tax($original_price, $product, $cart)
 {
     global $woocommerce;
     if (!WC_Subscriptions_Product::is_subscription($product['product_id'])) {
         return $original_price;
     }
     $price = $original_price;
     if (!empty($cart->applied_coupons)) {
         foreach ($cart->applied_coupons as $code) {
             $coupon = new WC_Coupon($code);
             if ($coupon->apply_before_tax() && $coupon->is_valid()) {
                 // Sign up fee discount
                 if ('sign_up_fee' == WC_Subscriptions_Cart::get_recalculation_type() && 'sign_up_fee' == $coupon->type || 'base_recurring_fee' == WC_Subscriptions_Cart::get_recalculation_type() && 'recurring_fee' == $coupon->type || 0 == WC_Subscriptions_Cart::get_cart_subscription_sign_up_fee() && 'recurring_fee' == $coupon->type) {
                     if ($original_price < $coupon->amount) {
                         $discount_amount = $original_price;
                     } else {
                         $discount_amount = $coupon->amount;
                     }
                     $price = $original_price - $coupon->amount;
                     if ($price < 0) {
                         $price = 0;
                     }
                     // add to discount totals
                     $woocommerce->cart->discount_cart = $woocommerce->cart->discount_cart + $discount_amount * $product['quantity'];
                 }
             }
         }
     }
     return $price;
 }
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:36,代码来源:class-wc-subscriptions-coupon.php


示例3: get_recurring_price_html_component

 /**
  * Returns the recurring price component of a subscription product.
  *
  * @param  WC_Product $product
  * @return string
  */
 public static function get_recurring_price_html_component($product)
 {
     $sync_date = $product->subscription_payment_sync_date;
     $product->subscription_payment_sync_date = 0;
     $sub_price_html = WC_Subscriptions_Product::get_price_string($product, array('price' => '%s', 'sign_up_fee' => false));
     $product->subscription_payment_sync_date = $sync_date;
     return $sub_price_html;
 }
开发者ID:alexbaron50,项目名称:Rockk3rs-Lab-Test,代码行数:14,代码来源:class-wc-pb-helpers.php


示例4: add_order_meta

 /**
  * When a new order is inserted, add the subscriptions period to the order. 
  * 
  * It's important that the period is tied to the order so that changing the products
  * period does not change the past. 
  *
  * @since 1.0
  */
 public static function add_order_meta($order_id)
 {
     global $woocommerce;
     if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
         $order = new WC_Order($order_id);
         $order_subscription_periods = array();
         $order_subscription_intervals = array();
         $order_subscription_lengths = array();
         $order_subscription_trial_lengths = array();
         foreach ($order->get_items() as $item) {
             $period = WC_Subscriptions_Product::get_period($item['id']);
             if (!empty($period)) {
                 $order_subscription_periods[$item['id']] = $period;
             }
             $interval = WC_Subscriptions_Product::get_interval($item['id']);
             if (!empty($interval)) {
                 $order_subscription_intervals[$item['id']] = $interval;
             }
             $length = WC_Subscriptions_Product::get_length($item['id']);
             if (!empty($length)) {
                 $order_subscription_lengths[$item['id']] = $length;
             }
             $trial_length = WC_Subscriptions_Product::get_trial_length($item['id']);
             if (!empty($trial_length)) {
                 $order_subscription_trial_lengths[$item['id']] = $trial_length;
             }
         }
         update_post_meta($order_id, '_order_subscription_periods', $order_subscription_periods);
         update_post_meta($order_id, '_order_subscription_intervals', $order_subscription_intervals);
         update_post_meta($order_id, '_order_subscription_lengths', $order_subscription_lengths);
         update_post_meta($order_id, '_order_subscription_trial_lengths', $order_subscription_trial_lengths);
         // Store sign-up fee details
         foreach (WC_Subscriptions_Cart::get_sign_up_fee_fields() as $field_name) {
             update_post_meta($order_id, "_{$field_name}", $woocommerce->cart->{$field_name});
         }
         // Prepare sign up fee taxes to store in same format as order taxes
         $sign_up_fee_taxes = array();
         foreach (array_keys($woocommerce->cart->sign_up_fee_taxes) as $key) {
             $is_compound = $woocommerce->cart->tax->is_compound($key) ? 1 : 0;
             $sign_up_fee_taxes[] = array('label' => $woocommerce->cart->tax->get_rate_label($key), 'compound' => $is_compound, 'cart_tax' => number_format($woocommerce->cart->sign_up_fee_taxes[$key], 2, '.', ''));
         }
         update_post_meta($order_id, '_sign_up_fee_taxes', $sign_up_fee_taxes);
     }
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:52,代码来源:class-wc-subscriptions-checkout.php


示例5: calculate_potential_monthly_maximum_payment_in_cart

 /**
  * Determine the maximum monthly payment required for subscriptions currently in cart.
  * This is an approximation based on 31 day months.
  *
  * @return float
  */
 protected function calculate_potential_monthly_maximum_payment_in_cart()
 {
     $potential_monthly_max = 0;
     foreach (WC()->cart->cart_contents as $cart_item) {
         $product_subscription = $cart_item['data'];
         $item_quantity = absint($cart_item['quantity']);
         if (WC_Subscriptions_Product::is_subscription($product_subscription)) {
             $subscription_price = (double) $product_subscription->subscription_price;
             $subscription_interval = (double) $product_subscription->subscription_period_interval;
             $subscription_monthly_max = $item_quantity * $subscription_price;
             if ('day' === $product_subscription->subscription_period) {
                 $subscription_monthly_max = $subscription_price * (31 / $subscription_interval);
             } else {
                 if ('week' === $product_subscription->subscription_period) {
                     $subscription_monthly_max = $subscription_price * ceil(4 / $subscription_interval);
                 }
             }
             $potential_monthly_max += $subscription_monthly_max;
         }
     }
     return $potential_monthly_max;
 }
开发者ID:lilweirdward,项目名称:blofishwordpress,代码行数:28,代码来源:class-wc-gateway-amazon-payments-advanced-subscriptions.php


示例6: save_subscription_meta

 /**
  * Save subscription details when edit product page is submitted for a subscription product type
  * or the bulk edit product is saved.
  * 
  * The $_REQUEST global is used to account for both $_GET submission from Bulk Edit page and 
  * $_POST submission from Edit Product page.
  * 
  * @param array Array of Product types & their labels, excluding the Subscription product type.
  * @return array Array of Product types & their labels, including the Subscription product type.
  * @since 1.0
  */
 public static function save_subscription_meta($post_id)
 {
     if (!WC_Subscriptions_Product::is_subscription($post_id)) {
         return;
     }
     if (isset($_REQUEST['_subscription_price'])) {
         update_post_meta($post_id, '_subscription_price', stripslashes($_REQUEST['_subscription_price']));
         update_post_meta($post_id, '_price', stripslashes($_REQUEST['_subscription_price']));
     } else {
         // Handle bulk edit, where _subscription_price field is not available
         if (isset($_REQUEST['_regular_price']) && !empty($_REQUEST['_regular_price'])) {
             update_post_meta($post_id, '_subscription_price', stripslashes($_REQUEST['_regular_price']));
             update_post_meta($post_id, '_price', stripslashes($_REQUEST['_regular_price']));
         } elseif (isset($_REQUEST['_sale_price']) && !empty($_REQUEST['_sale_price'])) {
             update_post_meta($post_id, '_subscription_price', stripslashes($_REQUEST['_sale_price']));
             update_post_meta($post_id, '_price', stripslashes($_REQUEST['_sale_price']));
         }
     }
     $subscription_fields = array('_subscription_sign_up_fee', '_subscription_period', '_subscription_period_interval', '_subscription_length', '_subscription_trial_length');
     foreach ($subscription_fields as $field_name) {
         if (isset($_REQUEST[$field_name])) {
             update_post_meta($post_id, $field_name, stripslashes($_REQUEST[$field_name]));
         }
     }
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:36,代码来源:class-wc-subscriptions-admin.php


示例7: get_sign_up_fee

 /**
  * Return the sign-up fee for this product
  *
  * @return string
  */
 public function get_sign_up_fee()
 {
     return WC_Subscriptions_Product::get_sign_up_fee($this);
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:9,代码来源:class-wc-product-subscription.php


示例8: is_sold_individually

 /**
  * Subscriptions are individual items so override the WC_Product is_sold_individually function
  * to reflect this.
  *
  * @since 1.0
  */
 public static function is_sold_individually($is_individual, $product)
 {
     // Sold individually if downloadable, virtual, and the option is enabled
     if (WC_Subscriptions_Product::is_subscription($product)) {
         $is_individual = true;
     }
     return $is_individual;
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:14,代码来源:woocommerce-subscriptions.php


示例9: maybe_trash_subscription

 /**
  * Clear all subscriptions from a user's account for a given order.
  *
  * @param $order WC_Order The order for which subscriptions should be cleared.
  * @since 1.0
  */
 public static function maybe_trash_subscription($order)
 {
     if (!is_object($order)) {
         $order = new WC_Order($order);
     }
     if (WC_Subscriptions_Order::order_contains_subscription($order)) {
         foreach ($order->get_items() as $order_item) {
             if (WC_Subscriptions_Product::is_subscription($order_item['id'])) {
                 self::trash_subscription($order->customer_user, self::get_subscription_key($order->id, $order_item['id']));
             }
         }
     }
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:19,代码来源:class-wc-subscriptions-manager.php


示例10: add_to_cart_text

 /**
  * Override the WooCommerce "Add to Cart" text with "Sign Up Now"
  *
  * @since 1.0
  */
 public static function add_to_cart_text($button_text)
 {
     global $product;
     if (WC_Subscriptions_Product::is_subscription($product)) {
         $button_text = get_option(WC_Subscriptions_Admin::$option_prefix . '_add_to_cart_button_text', __('Sign Up Now', self::$text_domain));
     }
     return $button_text;
 }
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:13,代码来源:woocommerce-subscriptions.php


示例11: get_cart_subscription_schemes

 /**
  * Returns subscription schemes for cart-level options.
  * Cart-level options will be displayed only if no cart-item is found with its own product-level subscription scheme.
  * This means that subscription options defined at product-level and "legacy" subscription-type products will "block" the display of cart-level options.
  *
  * In this case, cart-level options will be displayed at cart-item level.
  *
  * Must be called after all cart session data has been loaded.
  *
  * @return array|boolean
  */
 public static function get_cart_subscription_schemes()
 {
     $wcs_prefix = WC_Subscriptions_Admin::$option_prefix;
     $cart_level_subs_active = get_option($wcs_prefix . '_enable_cart_subscriptions', 'no');
     $cart_level_schemes = array();
     $cart_level_schemes_keys = array();
     if ($cart_level_subs_active === 'yes') {
         $cart_level_schemes = get_option($wcs_prefix . '_subscribe_to_cart_schemes', array());
     }
     if (empty($cart_level_schemes)) {
         return false;
     }
     foreach ($cart_level_schemes as $cart_level_scheme) {
         $cart_level_schemes_keys[] = $cart_level_scheme['id'];
     }
     foreach (WC()->cart->cart_contents as $cart_item) {
         if (!WCS_ATT_Cart::is_supported_product_type($cart_item)) {
             return false;
         }
         if ($cart_item_level_schemes = self::get_subscription_schemes($cart_item, 'cart-item')) {
             return false;
         }
         if (WC_Subscriptions_Product::is_subscription($cart_item['product_id'])) {
             return false;
         }
     }
     return $cart_level_schemes;
 }
开发者ID:titocalabrese,项目名称:woocommerce-subscribe-to-all-the-things,代码行数:39,代码来源:class-wcsatt-schemes.php


示例12: filter_price_html

 /**
  * Add subscription price string info to products with attached subscription schemes.
  *
  * @param  string     $price
  * @param  WC_Product $product
  * @return string
  */
 public static function filter_price_html($price, $product)
 {
     if (self::$bypass_price_html_filter) {
         return $price;
     }
     $subscription_schemes = WCS_ATT_Schemes::get_product_subscription_schemes($product);
     $has_product_level_schemes = empty($subscription_schemes) ? false : true;
     if ($has_product_level_schemes) {
         $force_subscription = get_post_meta($product->id, '_wcsatt_force_subscription', true);
         if ($force_subscription === 'yes') {
             $subscription_scheme = current($subscription_schemes);
             $overridden_prices = WCS_ATT_Schemes::get_subscription_scheme_prices($product, $subscription_scheme);
             $suffix = '';
             $_cloned = clone $product;
             $_cloned->is_converted_to_sub = 'yes';
             $_cloned->subscription_period = $subscription_scheme['subscription_period'];
             $_cloned->subscription_period_interval = $subscription_scheme['subscription_period_interval'];
             $_cloned->subscription_length = $subscription_scheme['subscription_length'];
             if (!empty($overridden_prices)) {
                 $_cloned->regular_price = $overridden_prices['regular_price'];
                 $_cloned->price = $overridden_prices['price'];
                 $_cloned->sale_price = $overridden_prices['sale_price'];
                 $_cloned->subscription_price = $overridden_prices['price'];
             }
             self::$bypass_price_html_filter = true;
             $price = $_cloned->get_price_html();
             self::$bypass_price_html_filter = false;
             $price = WC_Subscriptions_Product::get_price_string($_cloned, array('price' => $price));
             if (count($subscription_schemes) > 1 && false === strpos($price, $_cloned->get_price_html_from_text())) {
                 $price = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), $_cloned->get_price_html_from_text(), $price);
             }
         } else {
             $price_overrides_exist = WCS_ATT_Schemes::subscription_price_overrides_exist($subscription_schemes);
             $lowest_scheme_price = $product->price;
             $lowest_scheme_sale_price = $product->sale_price;
             $lowest_scheme_regular_price = $product->regular_price;
             $lowest_scheme_price_html = '';
             $from_price = '';
             if ($price_overrides_exist) {
                 foreach ($subscription_schemes as $subscription_scheme) {
                     $overridden_prices = WCS_ATT_Schemes::get_subscription_scheme_prices($product, $subscription_scheme);
                     if (!empty($overridden_prices)) {
                         if ($overridden_prices['price'] < $lowest_scheme_price) {
                             $lowest_scheme_price = $overridden_prices['price'];
                             $lowest_scheme_sale_price = $overridden_prices['sale_price'];
                             $lowest_scheme_regular_price = $overridden_prices['regular_price'];
                         }
                     }
                 }
                 if ($lowest_scheme_price < $product->price) {
                     $_cloned = clone $product;
                     $_cloned->is_converted_to_sub = 'yes';
                     $_cloned->subscription_period = $subscription_scheme['subscription_period'];
                     $_cloned->subscription_period_interval = $subscription_scheme['subscription_period_interval'];
                     $_cloned->subscription_length = $subscription_scheme['subscription_length'];
                     $_cloned->price = $lowest_scheme_price;
                     $_cloned->sale_price = $lowest_scheme_price;
                     $_cloned->regular_price = $lowest_scheme_regular_price;
                     self::$bypass_price_html_filter = true;
                     $lowest_scheme_price_html = $_cloned->get_price_html();
                     $lowest_scheme_price_html = WC_Subscriptions_Product::get_price_string($_cloned, array('price' => $lowest_scheme_price_html));
                     self::$bypass_price_html_filter = false;
                     if (count($subscription_schemes) > 1) {
                         $from_price = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), _x('<span class="from">from </span>', 'min-price: 1 plan available', WCS_ATT::TEXT_DOMAIN), $lowest_scheme_price_html);
                     } else {
                         $from_price = sprintf(_x('%1$s%2$s', 'Price range: from', WCS_ATT::TEXT_DOMAIN), _x('<span class="for">for </span>', 'min-price: multiple plans available', WCS_ATT::TEXT_DOMAIN), $lowest_scheme_price_html);
                     }
                 }
             }
             if ($price_overrides_exist) {
                 $suffix = ' <small class="wcsatt-sub-options">' . sprintf(_n('&ndash; or subscribe %s', '&ndash; or subscribe %s', count($subscription_schemes), WCS_ATT::TEXT_DOMAIN), $from_price) . '</small>';
             } else {
                 $suffix = ' <small class="wcsatt-sub-options">' . sprintf(_n('&ndash; subscription plan available', '&ndash; subscription plans available', count($subscription_schemes), WCS_ATT::TEXT_DOMAIN), $from_price) . '</small>';
             }
             $price = sprintf(__('%1$s%2$s', 'price html sub options suffix', WCS_ATT::TEXT_DOMAIN), $price, $suffix);
         }
     }
     return $price;
 }
开发者ID:VictorArgote,项目名称:woocommerce-subscribe-to-all-the-things,代码行数:86,代码来源:class-wcsatt-display.php


示例13: create_pending_subscription_for_order

 /**
  * Uses the details of an order to create a pending subscription on the customers account
  * for a subscription product, as specified with $product_id.
  *
  * @param int|WC_Order $order The order ID or WC_Order object to create the subscription from.
  * @param int $product_id The ID of the subscription product on the order.
  * @param array $args An array of name => value pairs to customise the details of the subscription, including:
  * 			'start_date' A MySQL formatted date/time string on which the subscription should start, in UTC timezone
  * 			'expiry_date' A MySQL formatted date/time string on which the subscription should expire, in UTC timezone
  * @since 1.1
  */
 public static function create_pending_subscription_for_order($order, $product_id, $args = array())
 {
     if (!is_object($order)) {
         $order = new WC_Order($order);
     }
     if (!WC_Subscriptions_Product::is_subscription($product_id)) {
         return;
     }
     $args = wp_parse_args($args, array('start_date' => '', 'expiry_date' => ''));
     $subscription_key = self::get_subscription_key($order->id, $product_id);
     // In case the subscription exists already
     $subscription = self::get_subscription($subscription_key);
     if (!empty($subscription['variation_id'])) {
         $product_id = $subscription['variation_id'];
     } elseif (!empty($subscription['product_id'])) {
         $product_id = $subscription['product_id'];
     }
     // Adding a new subscription so set the start date/time to now
     if (!empty($args['start_date'])) {
         if (is_numeric($args['start_date'])) {
             $args['start_date'] = date('Y-m-d H:i:s', $args['start_date']);
         }
         $start_date = $args['start_date'];
     } else {
         $start_date = !empty($subscription['start_date']) ? $subscription['start_date'] : gmdate('Y-m-d H:i:s');
     }
     // Adding a new subscription so set the expiry date/time from the order date
     if (!empty($args['expiry_date'])) {
         if (is_numeric($args['expiry_date'])) {
             $args['expiry_date'] = date('Y-m-d H:i:s', $args['expiry_date']);
         }
         $expiration = $args['expiry_date'];
     } else {
         $expiration = !empty($subscription['expiry_date']) ? $subscription['expiry_date'] : WC_Subscriptions_Product::get_expiration_date($product_id, $start_date);
     }
     // Adding a new subscription so set the expiry date/time from the order date
     $trial_expiration = !empty($subscription['trial_expiry_date']) ? $subscription['trial_expiry_date'] : WC_Subscriptions_Product::get_trial_expiration_date($product_id, $start_date);
     $failed_payments = !empty($subscription['failed_payments']) ? $subscription['failed_payments'] : 0;
     $completed_payments = !empty($subscription['completed_payments']) ? $subscription['completed_payments'] : array();
     $order_item_id = WC_Subscriptions_Order::get_item_id_by_subscription_key($subscription_key);
     // Store the subscription details in item meta
     woocommerce_add_order_item_meta($order_item_id, '_subscription_start_date', $start_date, true);
     woocommerce_add_order_item_meta($order_item_id, '_subscription_expiry_date', $expiration, true);
     woocommerce_add_order_item_meta($order_item_id, '_subscription_trial_expiry_date', $trial_expiration, true);
     woocommerce_add_order_item_meta($order_item_id, '_subscription_failed_payments', $failed_payments, true);
     woocommerce_add_order_item_meta($order_item_id, '_subscription_completed_payments', $completed_payments, true);
     woocommerce_add_order_item_meta($order_item_id, '_subscription_status', 'pending', true);
     woocommerce_add_order_item_meta($order_item_id, '_subscription_end_date', 0, true);
     woocommerce_add_order_item_meta($order_item_id, '_subscription_suspension_count', 0, true);
     $product = WC_Subscriptions::get_product($product_id);
     // Set subscription status to active and log activation
     $order->add_order_note(sprintf(__('Pending subscription created for "%s".', 'woocommerce-subscriptions'), $product->get_title()));
     do_action('pending_subscription_created_for_order', $order, $product_id);
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:65,代码来源:class-wc-subscriptions-manager.php


示例14: calculate_recurring_line_taxes

 /**
  * Calculate recurring line taxes when a store manager clicks the "Calc Line Tax" button on the "Edit Order" page.
  *
  * Based on the @see woocommerce_calc_line_taxes() function.
  * @since 1.2.4
  * @return void
  */
 public static function calculate_recurring_line_taxes()
 {
     global $woocommerce, $wpdb;
     check_ajax_referer('woocommerce-subscriptions', 'security');
     $tax = new WC_Tax();
     $taxes = $tax_rows = $item_taxes = $shipping_taxes = $return = array();
     $item_tax = 0;
     $order_id = absint($_POST['order_id']);
     $country = strtoupper(esc_attr($_POST['country']));
     $state = strtoupper(esc_attr($_POST['state']));
     $postcode = strtoupper(esc_attr($_POST['postcode']));
     $tax_class = esc_attr($_POST['tax_class']);
     if (isset($_POST['city'])) {
         $city = sanitize_title(esc_attr($_POST['city']));
     }
     $shipping = $_POST['shipping'];
     $line_subtotal = isset($_POST['line_subtotal']) ? esc_attr($_POST['line_subtotal']) : 0;
     $line_total = isset($_POST['line_total']) ? esc_attr($_POST['line_total']) : 0;
     $product_id = '';
     if (isset($_POST['order_item_id'])) {
         $product_id = woocommerce_get_order_item_meta($_POST['order_item_id'], '_product_id');
     } elseif (isset($_POST['product_id'])) {
         $product_id = esc_attr($_POST['product_id']);
     }
     if (!empty($product_id) && WC_Subscriptions_Product::is_subscription($product_id)) {
         // Get product details
         $product = WC_Subscriptions::get_product($product_id);
         $item_tax_status = $product->get_tax_status();
         if ($item_tax_status == 'taxable') {
             $tax_rates = $tax->find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class));
             $line_subtotal_taxes = $tax->calc_tax($line_subtotal, $tax_rates, false);
             $line_taxes = $tax->calc_tax($line_total, $tax_rates, false);
             $line_subtotal_tax = $tax->round(array_sum($line_subtotal_taxes));
             $line_tax = $tax->round(array_sum($line_taxes));
             if ($line_subtotal_tax < 0) {
                 $line_subtotal_tax = 0;
             }
             if ($line_tax < 0) {
                 $line_tax = 0;
             }
             $return = array('recurring_line_subtotal_tax' => $line_subtotal_tax, 'recurring_line_tax' => $line_tax);
             // Sum the item taxes
             foreach (array_keys($taxes + $line_taxes) as $key) {
                 $taxes[$key] = (isset($line_taxes[$key]) ? $line_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
             }
         }
         // Now calculate shipping tax
         $matched_tax_rates = array();
         $tax_rates = $tax->find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => ''));
         if ($tax_rates) {
             foreach ($tax_rates as $key => $rate) {
                 if (isset($rate['shipping']) && $rate['shipping'] == 'yes') {
                     $matched_tax_rates[$key] = $rate;
                 }
             }
         }
         $shipping_taxes = $tax->calc_shipping_tax($shipping, $matched_tax_rates);
         $shipping_tax = $tax->round(array_sum($shipping_taxes));
         $return['recurring_shipping_tax'] = $shipping_tax;
         // Remove old tax rows
         $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 AND order_item_type = 'recurring_tax' )", $order_id));
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d AND order_item_type = 'recurring_tax'", $order_id));
         // Get tax rates
         $rates = $wpdb->get_results("SELECT tax_rate_id, tax_rate_country, tax_rate_state, tax_rate_name, tax_rate_priority FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name");
         $tax_codes = array();
         foreach ($rates as $rate) {
             $code = array();
             $code[] = $rate->tax_rate_country;
             $code[] = $rate->tax_rate_state;
             $code[] = $rate->tax_rate_name ? sanitize_title($rate->tax_rate_name) : 'TAX';
             $code[] = absint($rate->tax_rate_priority);
             $tax_codes[$rate->tax_rate_id] = strtoupper(implode('-', array_filter($code)));
         }
         // Now merge to keep tax rows
         ob_start();
         foreach (array_keys($taxes + $shipping_taxes) as $key) {
             $item = array();
             $item['rate_id'] = $key;
             $item['name'] = $tax_codes[$key];
             $item['label'] = $tax->get_rate_label($key);
             $item['compound'] = $tax->is_compound($key) ? 1 : 0;
             $item['tax_amount'] = $tax->round(isset($taxes[$key]) ? $taxes[$key] : 0);
             $item['shipping_tax_amount'] = $tax->round(isset($shipping_taxes[$key]) ? $shipping_taxes[$key] : 0);
             if (!$item['label']) {
                 $item['label'] = $woocommerce->countries->tax_or_vat();
             }
             // Add line item
             $item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $item['name'], 'order_item_type' => 'recurring_tax'));
             // Add line item meta
             if ($item_id) {
                 woocommerce_add_order_item_meta($item_id, 'rate_id', $item['rate_id']);
                 woocommerce_add_order_item_meta($item_id, 'label', $item['label']);
                 woocommerce_add_order_item_meta($item_id, 'compound', $item['compound']);
//.........这里部分代码省略.........
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:101,代码来源:class-wc-subscriptions-order.php


示例15: adjust_access_granting_product_id

 /**
  * Adjust the product ID that grants access to a membership plan on purchase
  *
  * Subscription products take priority over all other products
  *
  * @since 1.0.0
  * @param int $product_id Product ID
  * @param array $access_granting_product_ids Array of product IDs
  * @param WC_Memberships_Membership_Plan $plan
  * @return int Product ID, adjusted if necessary
  */
 public function adjust_access_granting_product_id($product_id, $access_granting_product_ids, WC_Memberships_Membership_Plan $plan)
 {
     // Check if more than one products may grant access, and if the plan even
     // allows access while subscription is active
     if (count($access_granting_product_ids) > 1 && $this->plan_grants_access_while_subscription_active($plan->get_id())) {
         // First, find all subscription products that grant access
         $access_granting_subscription_product_ids = array();
         foreach ($access_granting_product_ids as $_product_id) {
             $product = wc_get_product($_product_id);
             if ($product->is_type(array('subscription', 'subscription_variation', 'variable-subscription'))) {
                 $access_granting_subscription_product_ids[] = $product->id;
             }
         }
         // If there are any, decide which one actually gets to grant access
         if (!empty($access_granting_subscription_product_ids)) {
             // Only one subscription grants access, short-circuit it as the winner
             if (count($access_granting_subscription_product_ids) == 1) {
                 $product_id = $access_granting_subscription_product_ids[0];
             } else {
                 $longest_expiration_date = 0;
                 foreach ($access_granting_subscription_product_ids as $_subscription_product_id) {
                     $expiration_date = WC_Subscriptions_Product::get_expiration_date($_subscription_product_id);
                     // No expiration date? Ladies and gentlemen - we've got a winner!
                     if (!$expiration_date) {
                         $product_id = $_subscription_product_id;
                         break;
                     }
                     // This one beats the previous sub! Out of the way, you sub-optimal sucker, you!
                     if (strtotime($expiration_date) > $longest_expiration_date) {
                         $product_id = $_subscription_product_id;
                         $longest_expiration_date = strtotime($expiration_date);
                     }
                 }
             }
         }
     }
     return $product_id;
 }
开发者ID:eugene-gromky-co,项目名称:mindfulnesssummit,代码行数:49,代码来源:class-wc-memberships-integration-subscriptions.php


示例16: set_prorated_price_for_calculation

 /**
  * Removes the "set_subscription_prices_for_calculation" filter from the WC Product's woocommerce_get_price hook once
  *
  * @since 1.5.10
  */
 public static function set_prorated_price_for_calculation($price, $product)
 {
     if (WC_Subscriptions_Product::is_subscription($product) && self::is_product_prorated($product) && in_array(WC_Subscriptions_Cart::get_calculation_type(), array('combined_total', 'none'))) {
         $next_payment_date = self::calculate_first_payment_date($product, 'timestamp');
         if (self::is_today($next_payment_date)) {
             return $price;
         }
         switch ($product->subscription_period) {
             case 'week':
                 $days_in_cycle = 7 * $product->subscription_period_interval;
                 break;
             case 'month':
                 $days_in_cycle = date('t') * $product->subscription_period_interval;
                 break;
             case 'year':
                 $days_in_cycle = (365 + date('L')) * $product->subscription_period_interval;
                 break;
         }
         $days_until_next_payment = ceil(($next_payment_date - gmdate('U')) / (60 * 60 * 24));
         if ('combined_total' == WC_Subscriptions_Cart::get_calculation_type()) {
             $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product);
             if ($sign_up_fee > 0 && 0 == WC_Subscriptions_Product::get_trial_length($product)) {
                 $price = $sign_up_fee + $days_until_next_payment * (($price - $sign_up_fee) / $days_in_cycle);
             }
         } elseif ('none' == WC_Subscriptions_Cart::get_calculation_type()) {
             $price = $days_until_next_payment * ($price / $days_in_cycle);
         }
     }
     return $price;
 }
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:35,代码来源:class-wc-subscriptions-synchroniser.php


示例17: is_purchasable

 /**
  * If a product is being marked as not purchasable because it is limited and the customer has a subscription,
  * but the current request is to switch the subscription, then mark it as purchasable.
  *
  * @since 1.4.4
  * @return bool
  */
 public static function is_purchasable($is_purchasable, $product)
 {
     global $woocommerce;
     if (false === $is_purchasable && WC_Subscriptions_Product::is_subscription($product->id) && 'yes' === $product->limit_subscriptions && WC_Subscriptions_Manager::user_has_subscription(0, $product->id, 'active')) {
         // Adding to cart from the product page
         if (isset($_GET['switch-subscription'])) {
             $is_purchasable = true;
             // Validating when restring cart from session
         } elseif (self::cart_contains_subscription_switch()) {
             $is_purchasable = true;
             // Restoring cart from session, so need to check the cart in the session (self::cart_contains_subscription_switch() only checks the cart)
         } elseif (isset($woocommerce->session->cart)) {
             foreach ($woocommerce->session->cart as $cart_item_key => $cart_item) {
                 if (isset($cart_item['subscription_switch'])) {
                     $is_purchasable = true;
                     break;
                 }
             }
         }
     }
     return $is_purchasable;
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:29,代码来源:class-wc-subscriptions-switcher.php


示例18: 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)
 {
     $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);
             if ($coupon->apply_before_tax() && $coupon->is_valid()) {
                 $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 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP WC_Tax类代码示例发布时间:2022-05-23
下一篇:
PHP WC_Subscriptions_Order类代码示例发布时间: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