本文整理汇总了PHP中WC_Subscriptions_Manager类的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager类的具体用法?PHP WC_Subscriptions_Manager怎么用?PHP WC_Subscriptions_Manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WC_Subscriptions_Manager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: process_scheduled_subscription_payment
/**
* process_scheduled_subscription_payment function.
*
* @param float $amount_to_charge The amount to charge.
* @param WC_Order $order The WC_Order object of the order which the subscription was purchased in.
* @param int $product_id The ID of the subscription product for which this payment relates.
*/
public function process_scheduled_subscription_payment($amount_to_charge, $order, $product_id)
{
$result = $this->process_subscription_payment($order, $amount_to_charge);
if (is_wp_error($result)) {
WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
} else {
WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
}
}
开发者ID:bmcgowan,项目名称:woocommerce-payeezy,代码行数:16,代码来源:class-wc-payeezy-gateway-addons-deprecated.php
示例2: scheduled_subscription_payment
/**
* scheduled_subscription_payment function.
*
* @param $amount_to_charge float The amount to charge.
* @param $order WC_Order The WC_Order object of the order which the subscription was purchased in.
* @param $product_id int The ID of the subscription product for which this payment relates.
* @access public
* @return void
*/
function scheduled_subscription_payment($amount_to_charge, $order, $product_id)
{
$result = $this->process_subscription_payment($order, $amount_to_charge);
if (is_wp_error($result)) {
$order->add_order_note(sprintf(__('eWAY subscription renewal failed - %s', 'wc-eway'), $this->response_message_lookup($result->get_error_message())));
WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
} else {
WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
}
}
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:19,代码来源:class-wc-gateway-eway-subscriptions.php
示例3: subscription_renew
/**
* Process period_created event from webhook
* @param $data array
**/
private function subscription_renew($data)
{
$cycle = $data->bill->period->cycle;
$subscription = $this->find_subscription_by_id($data->bill->subscription->code);
$vindi_subscription_id = $data->bill->subscription->id;
if ($this->subscription_has_order_in_cycle($vindi_subscription_id, $cycle)) {
throw new Exception('Já existe o ciclo $cycle para a assinatura ' . $vindi_subscription_id . ' pedido ' . $subscription->id);
}
WC_Subscriptions_Manager::prepare_renewal($subscription->id);
$order_id = $subscription->get_last_order();
$order = $this->find_order_by_id($order_id);
add_post_meta($order->id, 'vindi_wc_cycle', $cycle);
$this->container->logger->log('Novo Período criado: Pedido #' . $order->id);
}
开发者ID:vindi,项目名称:vindi-woocommerce-subscriptions,代码行数:18,代码来源:class-vindi-webhook-handler.php
示例4: filter_woocommerce_my_account_my_orders_actions
/**
* Customise which actions are shown against a subscriptions order on the My Account page.
*
* @since 1.3
*/
public static function filter_woocommerce_my_account_my_orders_actions($actions, $order)
{
if (WC_Subscriptions_Order::order_contains_subscription($order) || WC_Subscriptions_Renewal_Order::is_renewal($order)) {
unset($actions['cancel']);
if (is_numeric(get_post_meta($order->id, '_failed_order_replaced_by', true))) {
unset($actions['pay']);
}
$original_order = WC_Subscriptions_Renewal_Order::get_parent_order($order);
$order_items = WC_Subscriptions_Order::get_recurring_items($original_order);
$first_order_item = reset($order_items);
$product_id = WC_Subscriptions_Order::get_items_product_id($first_order_item);
$subscription_key = WC_Subscriptions_Manager::get_subscription_key($original_order->id, $product_id);
$subscription = WC_Subscriptions_Manager::get_users_subscription($original_order->customer_user, $subscription_key);
if (empty($subscription) || !in_array($subscription['status'], array('on-hold', 'pending'))) {
unset($actions['pay']);
}
}
return $actions;
}
开发者ID:bulats,项目名称:chef,代码行数:24,代码来源:class-wc-subscriptions-checkout.php
示例5: 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
示例6: processSubscriptions
private function processSubscriptions()
{
global $wpdb;
// check wether subscriptions addon is activated
if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($this->order)) {
$products = $this->order->get_items();
foreach ($products as $product) {
if (is_array($product) && isset($product['product_id']) && intval($product['product_id']) > 0 && isset($product['subscription_period']) && $product['subscription_period'] != '') {
// product is a subscription?
$woo_sub_key = WC_Subscriptions_Manager::get_subscription_key($this->order_id, $product['product_id']);
// required vars
$amount = floatval(WC_Subscriptions_Order::get_recurring_total($this->order)) * 100;
$currency = get_woocommerce_currency();
$interval = intval($product['subscription_interval']);
$period = strtoupper($product['subscription_period']);
$length = strtoupper($product['subscription_length']);
if ($length > 0) {
$periodOfValidity = $length . ' ' . $period;
} else {
$periodOfValidity = false;
}
$trial_end = strtotime(WC_Subscriptions_Product::get_trial_expiration_date($product['product_id'], get_gmt_from_date($this->order->order_date)));
if ($trial_end === false) {
$trial_time = 0;
} else {
$datediff = $trial_end - time();
$trial_time = ceil($datediff / (60 * 60 * 24));
}
// md5 name
$woo_sub_md5 = md5($amount . $currency . $interval . $trial_time);
// get offer
$name = 'woo_' . $product['product_id'] . '_' . $woo_sub_md5;
$offer = $this->subscriptions->offerGetDetailByName($name);
// check wether offer exists in paymill
if ($offer === false) {
// offer does not exist in paymill yet, create it
$params = array('amount' => $amount, 'currency' => $currency, 'interval' => $interval . ' ' . $period, 'name' => $name, 'trial_period_days' => intval($trial_time));
$offer = $this->subscriptions->offerCreate($params);
if ($GLOBALS['paymill_loader']->paymill_errors->status()) {
$GLOBALS['paymill_loader']->paymill_errors->getErrors();
return false;
}
}
// create user subscription
$user_sub = $this->subscriptions->create($this->clientClass->getCurrentClientID(), $offer, $this->paymentClass->getPaymentID(), isset($_POST['paymill_delivery_date']) ? $_POST['paymill_delivery_date'] : false, $periodOfValidity);
if ($GLOBALS['paymill_loader']->paymill_errors->status()) {
//maybe offer cache is outdated, recache and try again
$GLOBALS['paymill_loader']->paymill_errors->reset();
// reset error status
$this->subscriptions->offerGetList(true);
$params = array('amount' => $amount, 'currency' => $currency, 'interval' => $interval . ' ' . $period, 'name' => $name, 'trial_period_days' => intval($trial_time));
$offer = $this->subscriptions->offerCreate($params);
if ($GLOBALS['paymill_loader']->paymill_errors->status()) {
$GLOBALS['paymill_loader']->paymill_errors->getErrors();
return false;
}
$user_sub = $this->subscriptions->create($this->clientClass->getCurrentClientID(), $offer, $this->paymentClass->getPaymentID(), isset($_POST['paymill_delivery_date']) ? $_POST['paymill_delivery_date'] : false, $periodOfValidity);
if ($GLOBALS['paymill_loader']->paymill_errors->status()) {
$GLOBALS['paymill_loader']->paymill_errors->getErrors();
return false;
}
}
$wpdb->query($wpdb->prepare('INSERT INTO ' . $wpdb->prefix . 'paymill_subscriptions (paymill_sub_id, woo_user_id, woo_offer_id) VALUES (%s, %s, %s)', array($user_sub, get_current_user_id(), $woo_sub_key)));
// subscription successful
do_action('paymill_woocommerce_subscription_created', array('product_id' => $product['product_id'], 'offer_id' => $offer));
return true;
}
}
} else {
return true;
}
}
开发者ID:cyrrill,项目名称:paymill-wordpress,代码行数:72,代码来源:woocommerce.inc.php
示例7: get_price_string
/**
* Returns a string representing the details of the subscription.
*
* For example "$20 per Month for 3 Months with a $10 sign-up fee".
*
* @param WC_Product|int $product A WC_Product object or ID of a WC_Product.
* @param array $inclusions An associative array of flags to indicate how to calculate the price and what to include, values:
* 'tax_calculation' => false to ignore tax, 'include_tax' or 'exclude_tax' To indicate that tax should be added or excluded respectively
* 'subscription_length' => true to include subscription's length (default) or false to exclude it
* 'sign_up_fee' => true to include subscription's sign up fee (default) or false to exclude it
* 'price' => string a price to short-circuit the price calculations and use in a string for the product
* @since 1.0
*/
public static function get_price_string($product, $include = array())
{
if (!is_object($product)) {
$product = WC_Subscriptions::get_product($product);
}
if (!self::is_subscription($product)) {
return;
}
$include = wp_parse_args($include, array('tax_calculation' => false, 'subscription_price' => true, 'subscription_period' => true, 'subscription_length' => true, 'sign_up_fee' => true, 'trial_length' => true));
$include = apply_filters('woocommerce_subscriptions_product_price_string_inclusions', $include, $product);
$base_price = self::get_price($product);
if (true === $include['sign_up_fee']) {
$sign_up_fee = self::get_sign_up_fee($product);
} elseif (false !== $include['sign_up_fee']) {
// Allow override of product's sign-up fee
$sign_up_fee = $include['sign_up_fee'];
} else {
$sign_up_fee = 0;
}
if ($include['tax_calculation'] != false) {
if ($include['tax_calculation'] == 'exclude_tax') {
// Subtract Tax
$tax_per_period = self::calculate_tax_for_subscription($base_price, $product);
if (isset($include['price'])) {
$price = $include['price'];
} else {
$price = woocommerce_price($base_price - $tax_per_period);
}
if ($sign_up_fee > 0) {
$sign_up_tax = self::calculate_tax_for_subscription($sign_up_fee, $product);
$sign_up_fee = $sign_up_fee - $sign_up_tax;
}
} else {
// Add Tax
$tax_per_period = self::calculate_tax_for_subscription($base_price, $product, true);
if (isset($include['price'])) {
$price = $include['price'];
} else {
$price = woocommerce_price($base_price + $tax_per_period);
}
if ($sign_up_fee > 0) {
$sign_up_tax = self::calculate_tax_for_subscription($sign_up_fee, $product, true);
$sign_up_fee = $sign_up_fee - $sign_up_tax;
}
}
} else {
if (isset($include['price'])) {
$price = $include['price'];
} else {
$price = woocommerce_price($base_price);
}
}
$billing_interval = self::get_interval($product);
$subscription_length = self::get_length($product);
$trial_length = self::get_trial_length($product);
$trial_period = self::get_trial_period($product);
if (is_numeric($sign_up_fee)) {
$sign_up_fee = woocommerce_price($sign_up_fee);
}
if ($include['subscription_length']) {
$ranges = WC_Subscriptions_Manager::get_subscription_ranges(self::get_period($product));
}
if ($include['subscription_length'] && $subscription_length != 0) {
$include_length = true;
} else {
$include_length = false;
}
$subscription_string = '';
if ($include['subscription_price'] && $include['subscription_period']) {
// Allow extensions to not show price or billing period e.g. Name Your Price
if ($include_length && $subscription_length == $billing_interval) {
$subscription_string = $price;
// Only for one billing period so show "$5 for 3 months" instead of "$5 every 3 months for 3 months"
} else {
$subscription_string = sprintf(_n(' %s / %s', ' %s every %s', $billing_interval, 'woocommerce-subscriptions'), $price, WC_Subscriptions_Manager::get_subscription_period_strings($billing_interval, self::get_period($product)));
}
} elseif ($include['subscription_price']) {
$subscription_string = $price;
} elseif ($include['subscription_period']) {
$subscription_string = sprintf(_n('%s', 'every %s', $billing_interval, 'woocommerce-subscriptions'), WC_Subscriptions_Manager::get_subscription_period_strings($billing_interval, self::get_period($product)));
}
// Add the length to the end
if ($include_length) {
$subscription_string = sprintf(__('%s for %s', 'woocommerce-subscriptions'), $subscription_string, $ranges[$subscription_length]);
}
if ($include['trial_length'] && $trial_length != 0) {
$trial_string = WC_Subscriptions_Manager::get_subscription_trial_period_strings($trial_length, $trial_period);
//.........这里部分代码省略.........
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:101,代码来源:class-wc-subscriptions-product.php
示例8: sensei_woocommerce_reactivate_subscription
/**
* Runs when an subscription is re-activated after suspension.
* @since 1.3.3
* @access public
* @param integer $user_id User ID
* @param integer $subscription_key Subscription Unique Key
* @return void
*/
public function sensei_woocommerce_reactivate_subscription($user_id, $subscription_key)
{
$subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key);
$order = new WC_Order($subscription['order_id']);
$user = get_user_by('id', $order->user_id);
$order_user = array();
$order_user['ID'] = $user->ID;
$order_user['user_login'] = $user->user_login;
$order_user['user_email'] = $user->user_email;
$order_user['user_url'] = $user->user_url;
$courses = $this->post_types->course->get_product_courses($subscription['product_id']);
foreach ($courses as $course_item) {
$update_course = $this->woocommerce_course_update($course_item->ID, $order_user);
}
// End For Loop
}
开发者ID:drumchannel,项目名称:drumchannel-dev,代码行数:24,代码来源:class-woothemes-sensei.php
示例9: can_subscription_be_changed_to
/**
* Add a 'new-payment-method' handler to the @see WC_Subscriptions_Manager::can_subscription_be_changed_to() function
* to determine whether the recurring payment method on a subscription can be changed.
*
* For the recurring payment method to be changeable, the subscription must be active, have future (automatic) payments
* and use a payment gateway which allows the subscription to be cancelled.
*
* @param bool $subscription_can_be_changed Flag of whether the subscription can be changed to
* @param string $new_status_or_meta The status or meta data you want to change th subscription to. Can be 'active', 'on-hold', 'cancelled', 'expired', 'trash', 'deleted', 'failed', 'new-payment-date' or some other value attached to the 'woocommerce_can_subscription_be_changed_to' filter.
* @param object $args Set of values used in @see WC_Subscriptions_Manager::can_subscription_be_changed_to() for determining if a subscription can be changes, include:
* 'subscription_key' string A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
* 'subscription' array Subscription of the form returned by @see WC_Subscriptions_Manager::get_subscription()
* 'user_id' int The ID of the subscriber.
* 'order' WC_Order The order which recorded the successful payment (to make up for the failed automatic payment).
* 'payment_gateway' WC_Payment_Gateway The subscription's recurring payment gateway
* 'order_uses_manual_payments' bool A boolean flag indicating whether the subscription requires manual renewal payment.
* @since 1.4
*/
public static function can_subscription_be_changed_to($subscription_can_be_changed, $new_status_or_meta, $args)
{
global $woocommerce;
if ('new-payment-method' === $new_status_or_meta) {
$next_payment_timestamp = WC_Subscriptions_Manager::get_next_payment_date($args->subscription_key, '', 'timestamp');
// Check if any payment gateway supports recurring payment method changes
$one_gateway_supports_changes = false;
foreach ($woocommerce->payment_gateways->get_available_payment_gateways() as $gateway) {
if ($gateway->supports('subscription_payment_method_change')) {
$one_gateway_supports_changes = true;
break;
}
}
if ($one_gateway_supports_changes && 0 !== $next_payment_timestamp && false === $args->order_uses_manual_payments && $args->payment_gateway->supports('subscription_cancellation') && 'active' == $args->subscription['status']) {
$subscription_can_be_changed = true;
} else {
$subscription_can_be_changed = false;
}
}
return $subscription_can_be_changed;
}
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:39,代码来源:class-wc-subscriptions-change-payment-gateway.php
示例10: 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
示例11: maybe_reschedule_subscription_payment
* @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
* @since 1.1.5
* @deprecated 2.0
*/
public static function maybe_reschedule_subscription_payment($user_id, $subscription_key)
{
_deprecated_function(__METHOD__, '2.0');
$subscription = wcs_get_subscription_from_key($subscription_key);
// Don't reschedule for cancelled, suspended or expired subscriptions
if (!$subscription->has_status('expired', 'cancelled', 'on-hold')) {
// Reschedule the 'scheduled_subscription_payment' hook
if ($subscription->can_date_be_updated('next_payment')) {
$subscription->update_dates(array('next_payment' => $subscription->calculate_date('next_payment')));
do_action('rescheduled_subscription_payment', $user_id, $subscription_key);
}
}
}
/**
* Fires when the trial period for a subscription has completed.
*
* @param int $subscription_id The ID of a 'shop_subscription' post
* @since 1.0
* @deprecated 2.0
*/
public static function subscription_trial_end($subscription_id, $deprecated = null)
{
_deprecated_function(__METHOD__, '2.0');
}
}
WC_Subscriptions_Manager::init();
开发者ID:DustinHartzler,项目名称:TheCLEFT,代码行数:30,代码来源:class-wc-subscriptions-manager.php
示例12: is_purchasable
/**
* Checks if the store manager has requested the current product be limited to one purchase
* per customer, and if so, checks whether the customer already has an active subscription to
* the product.
*
* @access public
* @return bool
*/
function is_purchasable()
{
$purchasable = parent::is_purchasable();
if (true === $purchasable && 'yes' == $this->limit_subscriptions) {
if (WC_Subscriptions_Manager::user_has_subscription(0, $this->id, 'active')) {
$purchasable = false;
}
}
return apply_filters('woocommerce_subscription_is_purchasable', $purchasable, $this);
}
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:18,代码来源:class-wc-product-subscription.php
示例13: get_subscription_price_string
/**
* Creates a subscription price string from an array of subscription details. For example, ""$5 / month for 12 months".
*
* @param array $subscription_details A set of name => value pairs for the subscription details to include in the string. Available keys:
* 'initial_amount': The upfront payment for the subscription, including sign up fees, as a string from the @see woocommerce_price(). Default empty string (no initial payment)
* 'initial_description': The word after the initial payment amount to describe the amount. Examples include "now" or "initial payment". Defaults to "up front".
* 'recurring_amount': The amount charged per period. Default 0 (no recurring payment).
* 'subscription_interval': How regularly the subscription payments are charged. Default 1, meaning each period e.g. per month.
* 'subscription_period': The temporal period of the subscription. Should be one of {day|week|month|year} as used by @see self::get_subscription_period_strings()
* 'subscription_length': The total number of periods the subscription should continue for. Default 0, meaning continue indefinitely.
* 'trial_length': The total number of periods the subscription trial period should continue for. Default 0, meaning no trial period.
* 'trial_period': The temporal period for the subscription's trial period. Should be one of {day|week|month|year} as used by @see self::get_subscription_period_strings()
* @since 1.2
* @return float $proportion A proportion of the total (e.g. 0.5 is half of the total)
*/
public static function get_subscription_price_string($subscription_details)
{
$subscription_details = wp_parse_args($subscription_details, array('initial_amount' => '', 'initial_description' => __('up front', WC_Subscriptions::$text_domain), 'recurring_amount' => '', 'subscription_interval' => 1, 'subscription_period' => '', 'subscription_length' => 0, 'trial_length' => 0, 'trial_period' => ''));
$subscription_details['subscription_period'] = strtolower($subscription_details['subscription_period']);
// Make sure prices have been through woocommerce_price()
$initial_amount_string = is_numeric($subscription_details['initial_amount']) ? woocommerce_price($subscription_details['initial_amount']) : $subscription_details['initial_amount'];
$recurring_amount_string = is_numeric($subscription_details['recurring_amount']) ? woocommerce_price($subscription_details['recurring_amount']) : $subscription_details['recurring_amount'];
$subscription_period_string = WC_Subscriptions_Manager::get_subscription_period_strings($subscription_details['subscription_interval'], $subscription_details['subscription_period']);
$subscription_ranges = WC_Subscriptions_Manager::get_subscription_ranges();
if ($subscription_details['subscription_length'] > 0 && $subscription_details['subscription_length'] == $subscription_details['subscription_interval']) {
if (!empty($subscription_details['initial_amount'])) {
$subscription_string = sprintf(__('%s %s then %s', WC_Subscriptions::$text_domain), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string);
} else {
$subscription_string = $recurring_amount_string;
}
} elseif (!empty($subscription_details['initial_amount'])) {
$subscription_string = sprintf(_n('%s %s then %s / %s', '%s %s then %s every %s', $subscription_details['subscription_interval'], WC_Subscriptions::$text_domain), $initial_amount_string, $subscription_details['initial_description'], $recurring_amount_string, $subscription_period_string);
} elseif (!empty($subscription_details['recurring_amount'])) {
$subscription_string = sprintf(_n('%s / %s', ' %s every %s', $subscription_details['subscription_interval'], WC_Subscriptions::$text_domain), $recurring_amount_string, $subscription_period_string);
} else {
$subscription_string = '';
}
if ($subscription_details['subscription_length'] > 0) {
$subscription_string = sprintf(__('%s for %s', WC_Subscriptions::$text_domain), $subscription_string, $subscription_ranges[$subscription_details['subscription_period']][$subscription_details['subscription_length']]);
}
if ($subscription_details['trial_length'] > 1 || empty($subscription_details['initial_amount']) && $subscription_details['trial_length'] > 0) {
$trial_length = self::get_subscription_trial_period_strings($subscription_details['trial_length'], $subscription_details['trial_period']);
if (!empty($subscription_details['initial_amount'])) {
$subscription_string = sprintf(__('%s with %s free trial', WC_Subscriptions::$text_domain), $subscription_string, $trial_length);
} else {
$subscription_string = sprintf(__('%s free trial then %s', WC_Subscriptions::$text_domain), ucfirst($trial_length), $subscription_string);
}
}
return apply_filters('woocommerce_subscription_price_string', $subscription_string, $subscription_details);
}
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:50,代码来源:class-wc-subscriptions-manager.php
示例14: get_subscriptions
//.........这里部分代码省略.........
$query .= "\n\t\t\t\tLEFT JOIN (\n\t\t\t\t\tSELECT `{$wpdb->prefix}woocommerce_order_items`.order_item_id, `{$wpdb->prefix}woocommerce_order_items`.order_id FROM `{$wpdb->prefix}woocommerce_order_items`\n\t\t\t\t\tWHERE `{$wpdb->prefix}woocommerce_order_items`.order_item_type = 'line_item'\n\t\t\t\t) AS order_ids USING (order_item_id)";
break;
case 'renewal_order_count':
$query .= "\n\t\t\t\tLEFT JOIN (\n\t\t\t\t\tSELECT items2.order_item_id, items2.order_id, r2.renewal_order_count FROM `{$wpdb->prefix}woocommerce_order_items` AS items2\n\t\t\t\t\tLEFT JOIN (\n\t\t\t\t\t\tSELECT posts.post_parent, COUNT(posts.ID) as renewal_order_count FROM `{$wpdb->prefix}posts` AS posts\n\t\t\t\t\t\tWHERE posts.post_parent != 0\n\t\t\t\t\t\tAND posts.post_type = 'shop_order'\n\t\t\t\t\t\tGROUP BY posts.post_parent\n\t\t\t\t\t) AS r2 ON r2.post_parent = items2.order_id\n\t\t\t\t\tWHERE items2.order_item_type = 'line_item'\n\t\t\t\t) AS renewals USING (order_item_id)";
break;
case 'user_display_name':
case 'user':
if (empty($args['customer_id'])) {
$query .= "\n\t\t\t\tLEFT JOIN (\n\t\t\t\t\tSELECT items2.order_item_id, items2.order_id, users.display_name FROM `{$wpdb->prefix}woocommerce_order_items` AS items2\n\t\t\t\t\tLEFT JOIN (\n\t\t\t\t\t\tSELECT postmeta.post_id, postmeta.meta_value, u.display_name FROM `{$wpdb->prefix}postmeta` AS postmeta\n\t\t\t\t\t\tLEFT JOIN (\n\t\t\t\t\t\t\tSELECT `{$wpdb->prefix}users`.ID, `{$wpdb->prefix}users`.display_name FROM `{$wpdb->prefix}users`\n\t\t\t\t\t\t) AS u ON u.ID = postmeta.meta_value\n\t\t\t\t\t\tWHERE postmeta.meta_key = '_customer_user'\n\t\t\t\t\t) AS users ON users.post_id = items2.order_id\n\t\t\t\t\tWHERE items2.order_item_type = 'line_item'\n\t\t\t\t) AS users_items USING (order_item_id)";
}
case 'last_payment_date':
// Because we need the date of the last renewal order (or maybe the original order if there are no renewal orders)
$query .= "\n\t\t\t\tLEFT JOIN (\n\t\t\t\t\tSELECT items2.order_item_id, (CASE WHEN (r2.renewal_order_count > 0) THEN l.last_payment_date ELSE o.order_date END) AS last_payment_date FROM `{$wpdb->prefix}woocommerce_order_items` AS items2\n\t\t\t\t\tLEFT JOIN (\n\t\t\t\t\t\tSELECT posts.post_parent, COUNT(posts.ID) as renewal_order_count FROM `{$wpdb->prefix}posts` AS posts\n\t\t\t\t\t\tWHERE posts.post_parent != 0\n\t\t\t\t\t\tAND posts.post_type = 'shop_order'\n\t\t\t\t\t\tGROUP BY posts.post_parent\n\t\t\t\t\t) AS r2 ON r2.post_parent = items2.order_id\n\t\t\t\t\tLEFT JOIN (\n\t\t\t\t\t\tSELECT o.ID, o.post_date_gmt AS order_date FROM `{$wpdb->prefix}posts` AS o\n\t\t\t\t\t\tWHERE o.post_type = 'shop_order'\n\t\t\t\t\t\tAND o.post_parent = 0\n\t\t\t\t\t) AS o ON o.ID = items2.order_id\n\t\t\t\t\tLEFT JOIN (\n\t\t\t\t\t\tSELECT p.ID, p.post_parent, MAX(p.post_date_gmt) AS last_payment_date FROM `{$wpdb->prefix}posts` AS p\n\t\t\t\t\t\tWHERE p.post_type = 'shop_order'\n\t\t\t\t\t\tAND p.post_parent != 0\n\t\t\t\t\t\tGROUP BY p.post_parent\n\t\t\t\t\t) AS l ON l.post_parent = items2.order_id\n\t\t\t\t\tWHERE items2.order_item_type = 'line_item'\n\t\t\t\t) AS payment_dates USING (order_item_id)";
break;
}
// Start where query
$query .= "\n\t\t\t\tWHERE 1=1";
// We only want subscriptions from within the product filter subclause
if (!empty($args['product_id']) || !empty($args['variation_id'])) {
$query .= "\n\t\t\t\tAND a.order_item_id = p.order_item_id";
}
// We only want subscriptions from within the status filter subclause
if (!empty($args['subscription_status']) && 'any' !== $args['subscription_status'] && '_subscription_status' !== $args['orderby']) {
$query .= "\n\t\t\t\tAND a.order_item_id = s.order_item_id";
}
// We only want items from a certain order
if (!empty($args['order_id'])) {
$order_ids = is_array($args['order_id']) ? implode(',', $args['order_id']) : $args['order_id'];
$query .= sprintf("\n\t\t\t\tAND a.order_item_id IN (\n\t\t\t\t\tSELECT o.order_item_id FROM `{$wpdb->prefix}woocommerce_order_items` AS o\n\t\t\t\t\tWHERE o.order_id IN (%s)\n\t\t\t\t)", $order_ids);
}
// If we only want subscriptions for a certain customer ID, we need to make sure items are from the customer's orders
if (!empty($args['customer_id'])) {
$query .= sprintf("\n\t\t\t\tAND a.order_item_id IN (\n\t\t\t\t\tSELECT `{$wpdb->prefix}woocommerce_order_items`.order_item_id FROM `{$wpdb->prefix}woocommerce_order_items`\n\t\t\t\t\tWHERE `{$wpdb->prefix}woocommerce_order_items`.order_id IN (\n\t\t\t\t\t\tSELECT `{$wpdb->prefix}postmeta`.post_id FROM `{$wpdb->prefix}postmeta`\n\t\t\t\t\t\tWHERE `{$wpdb->prefix}postmeta`.meta_key = '_customer_user'\n\t\t\t\t\t\tAND `{$wpdb->prefix}postmeta`.meta_value = %s\n\t\t\t\t\t)\n\t\t\t\t)", $args['customer_id']);
}
// Now we need to sort the subscriptions, which may mean selecting a specific bit of meta data
switch ($args['orderby']) {
case '_subscription_start_date':
case '_subscription_expiry_date':
case '_subscription_trial_expiry_date':
case '_subscription_end_date':
$query .= sprintf("\n\t\t\t\tAND a.meta_key = '%s'\n\t\t\t\tORDER BY CASE WHEN CAST(a.meta_value AS DATETIME) IS NULL THEN 1 ELSE 0 END, CAST(a.meta_value AS DATETIME) %s", $args['orderby'], $order_query);
break;
case '_subscription_status':
$query .= "\n\t\t\t\tAND a.meta_key = '_subscription_status'\n\t\t\t\tORDER BY a.meta_value" . $order_query;
break;
case '_product_id':
if (empty($args['product_id'])) {
$query .= "\n\t\t\t\tAND a2.order_item_id = a.order_item_id\n\t\t\t\tAND a.meta_key = '_product_id'\n\t\t\t\tORDER BY a.meta_value" . $order_query;
}
break;
case '_order_item_name':
case 'name':
if (empty($args['product_id'])) {
$query .= "\n\t\t\t\tAND a.meta_key = '_subscription_start_date'\n\t\t\t\tAND names.order_item_id = a.order_item_id\n\t\t\t\tORDER BY names.order_item_name" . $order_query . ", CASE WHEN CAST(a.meta_value AS DATETIME) IS NULL THEN 1 ELSE 0 END, CAST(a.meta_value AS DATETIME) DESC";
}
break;
case 'order_id':
$query .= "\n\t\t\t\tAND a.meta_key = '_subscription_start_date'\n\t\t\t\tAND order_ids.order_item_id = a.order_item_id\n\t\t\t\tORDER BY order_ids.order_id" . $order_query;
break;
case 'renewal_order_count':
$query .= "\n\t\t\t\tAND a.meta_key = '_subscription_start_date'\n\t\t\t\tAND renewals.order_item_id = a.order_item_id\n\t\t\t\tORDER BY renewals.renewal_order_count" . $order_query;
break;
case 'user_display_name':
case 'user':
if (empty($args['customer_id'])) {
$query .= "\n\t\t\t\tAND a.meta_key = '_subscription_start_date'\n\t\t\t\tAND users_items.order_item_id = a.order_item_id\n\t\t\t\tORDER BY users_items.display_name" . $order_query . ", CASE WHEN CAST(a.meta_value AS DATETIME) IS NULL THEN 1 ELSE 0 END, CAST(a.meta_value AS DATETIME) DESC";
}
break;
case 'last_payment_date':
$query .= "\n\t\t\t\tAND a.meta_key = '_subscription_start_date'\n\t\t\t\tAND payment_dates.order_item_id = a.order_item_id\n\t\t\t\tORDER BY payment_dates.last_payment_date" . $order_query;
break;
}
// Paging
if (-1 !== $args['subscriptions_per_page']) {
$query .= $limit_query;
}
$query .= "\n\t\t\t) AS a3 USING (order_item_id)";
// Add renewal order count & last payment date (there is duplication here when ordering by renewal order count or last payment date, but it's an arbitrary performance hit)
$query .= "\n\t\t\tLEFT JOIN (\n\t\t\t\tSELECT `{$wpdb->prefix}posts`.post_parent, COUNT(`{$wpdb->prefix}posts`.ID) as renewal_order_count FROM `{$wpdb->prefix}posts`\n\t\t\t\tWHERE `{$wpdb->prefix}posts`.post_parent != 0\n\t\t\t\tAND `{$wpdb->prefix}posts`.post_type = 'shop_order'\n\t\t\t\tGROUP BY `{$wpdb->prefix}posts`.post_parent\n\t\t\t) AS r ON r.post_parent = items.order_id\n\t\t\tLEFT JOIN (\n\t\t\t\tSELECT o.ID, o.post_date_gmt AS order_date FROM `{$wpdb->prefix}posts` AS o\n\t\t\t\tWHERE o.post_type = 'shop_order'\n\t\t\t\tAND o.post_parent = 0\n\t\t\t) AS o ON o.ID = items.order_id\n\t\t\tLEFT JOIN (\n\t\t\t\tSELECT p.ID, p.post_parent, MAX(p.post_date_gmt) AS last_payment_date FROM `{$wpdb->prefix}posts` AS p\n\t\t\t\tWHERE p.post_type = 'shop_order'\n\t\t\t\tAND p.post_parent != 0\n\t\t\t\tGROUP BY p.post_parent\n\t\t\t) AS l ON l.post_parent = items.order_id";
$query .= "\n\t\t\tWHERE meta.meta_key REGEXP '_subscription_(.*)|_product_id|_variation_id'\n\t\t\tAND meta.order_item_id = a3.order_item_id";
$query = apply_filters('woocommerce_get_subscriptions_query', $query, $args);
$raw_subscriptions = $wpdb->get_results($query);
// Create a backward compatible structure
foreach ($raw_subscriptions as $raw_subscription) {
if (!isset($raw_subscription->order_item_id)) {
continue;
}
if (!array_key_exists($raw_subscription->order_item_id, $subscriptions)) {
$subscriptions[$raw_subscription->order_item_id] = array('order_id' => $raw_subscription->order_id, 'name' => $raw_subscription->order_item_name, 'renewal_order_count' => empty($raw_subscription->renewal_order_count) ? 0 : $raw_subscription->renewal_order_count, 'last_payment_date' => $raw_subscription->last_payment_date);
$subscriptions[$raw_subscription->order_item_id]['user_id'] = get_post_meta($raw_subscription->order_id, '_customer_user', true);
}
$meta_key = str_replace('_subscription', '', $raw_subscription->meta_key);
$meta_key = substr($meta_key, 0, 1) == '_' ? substr($meta_key, 1) : $meta_key;
if ('product_id' === $meta_key) {
$subscriptions[$raw_subscription->order_item_id]['subscription_key'] = WC_Subscriptions_Manager::get_subscription_key($subscriptions[$raw_subscription->order_item_id]['order_id'], $raw_subscription->meta_value);
}
$subscriptions[$raw_subscription->order_item_id][$meta_key] = maybe_unserialize($raw_subscription->meta_value);
}
return apply_filters('woocommerce_get_subscriptions', $subscriptions, $args);
}
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:101,代码来源:woocommerce-subscriptions.php
示例15: wc_subs_exporter_get_filtered_subscriptions
function wc_subs_exporter_get_filtered_subscriptions($export)
{
global $wpdb;
$subscriptions = $filtered_subscriptions = array();
$sql = "SELECT DISTINCT i.order_id, m.product_id, p.meta_value\n\t\t\t\tFROM\n\t\t\t\t(\n\t\t\t\tSELECT order_item_id,\n\t\t\t\tMAX(CASE WHEN meta_key = '_product_id' THEN meta_value END) product_id\n\t\t\t\tFROM {$wpdb->prefix}woocommerce_order_itemmeta\n\t\t\t\tWHERE meta_key LIKE '_subscription%' \n\t\t\t\t\tOR meta_key LIKE '_recurring%'\n\t\t\t\t\tOR meta_key = '_product_id'\n\t\t\t\tGROUP BY order_item_id\n\t\t\t\tHAVING MAX(meta_key LIKE '_subscription%')\n\t\t\t\t\t+ MAX(meta_key LIKE '_recurring%') > 0\n\t\t\t\t) m JOIN {$wpdb->prefix}woocommerce_order_items i \n\t\t\t\tON m.order_item_id = i.order_item_id \n\t\t\t\tLEFT JOIN {$wpdb->prefix}postmeta p \n\t\t\t\tON i.order_id = p.post_id \n\t\t\t\tAND p.meta_key = '_customer_user'\n\t\t\t\tLEFT JOIN {$wpdb->prefix}posts po \n\t\t\t\tON p.post_id = po.ID\n\t\t\t\tWHERE po.post_type = 'shop_order' AND po.post_parent = 0";
$order_ids_and_product_ids = $wpdb->get_results($sql);
foreach ($order_ids_and_product_ids as $order_id_and_product_id) {
if (empty($order_id_and_product_id->product_id)) {
continue;
}
$subscription_key = $order_id_and_product_id->order_id . '_' . $order_id_and_product_id->product_id;
$subscription = WC_Subscriptions_Manager::get_subscription($subscription_key);
if (empty($subscription)) {
continue;
}
// filter status
if (!array_key_exists($subscription['status'], $export->status)) {
continue;
}
// filter dates
if ($export->dates_from && strtotime($subscription['start_date']) < strtotime($export->dates_from)) {
continue;
} elseif ($export->dates_to && strtotime($subscription['start_date']) > strtotime($export->dates_to)) {
continue;
}
$subscriptions[$order_id_and_product_id->meta_value][$subscription_key] = $subscription;
}
$processed_rows = 0;
foreach ($subscriptions as $user => $user_subscriptions) {
if (++$processed_rows <= $export->offset) {
continue;
}
foreach ($user_subscriptions as $key => $subscription) {
$filtered_subscriptions[$user][$key] = $subscription;
}
if ($processed_rows == $export->limit_volume) {
break;
}
}
return $filtered_subscriptions;
}
开发者ID:arobbins,项目名称:spellestate,代码行数:41,代码来源:functions.php
示例16: do_subscriptions_shortcode
|
请发表评论