本文整理汇总了PHP中WC_Subscriptions_Manager::get_subscription_expiration_date方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::get_subscription_expiration_date方法的具体用法?PHP WC_Subscriptions_Manager::get_subscription_expiration_date怎么用?PHP WC_Subscriptions_Manager::get_subscription_expiration_date使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Manager
的用法示例。
在下文中一共展示了WC_Subscriptions_Manager::get_subscription_expiration_date方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process_paypal_ipn_request
//.........这里部分代码省略.........
} else {
self::$log->add('paypal', 'IPN subscription sign up completed for order ' . $order_id);
}
}
break;
case 'subscr_payment':
if ('completed' == strtolower($transaction_details['payment_status'])) {
// Store PayPal Details
update_post_meta($order_id, 'PayPal Transaction ID', $transaction_details['txn_id']);
update_post_meta($order_id, 'Payer PayPal first name', $transaction_details['first_name']);
update_post_meta($order_id, 'Payer PayPal last name', $transaction_details['last_name']);
update_post_meta($order_id, 'PayPal Payment type', $transaction_details['payment_type']);
// Subscription Payment completed
$order->add_order_note(__('IPN subscription payment completed.', WC_Subscriptions::$text_domain));
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription payment completed for order ' . $order_id);
}
// First payment on order, process payment & activate subscription
if ($is_first_payment) {
$order->payment_complete();
WC_Subscriptions_Manager::activate_subscriptions_for_order($order);
} else {
// We don't need to reactivate the subscription because Subs didn't suspend it
remove_action('reactivated_subscription_paypal', __CLASS__ . '::reactivate_subscription_with_paypal', 10, 2);
WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
add_action('reactivated_subscription_paypal', __CLASS__ . '::reactivate_subscription_with_paypal', 10, 2);
}
} elseif ('failed' == strtolower($transaction_details['payment_status'])) {
// Subscription Payment completed
$order->add_order_note(__('IPN subscription payment failed.', WC_Subscriptions::$text_domain));
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription payment failed for order ' . $order_id);
}
// First payment on order, don't generate a renewal order
if ($is_first_payment) {
remove_action('processed_subscription_payment_failure', 'WC_Subscriptions_Renewal_Order::generate_failed_payment_renewal_order', 10, 2);
}
WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
} else {
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription payment notification received for order ' . $order_id . ' with status ' . $transaction_details['payment_status']);
}
}
break;
case 'subscr_cancel':
if ('true' == get_post_meta($order_id, '_wcs_changing_payment_from_paypal_to_paypal', true)) {
// The flag has served its purpose
delete_post_meta($order_id, '_wcs_changing_payment_from_paypal_to_paypal');
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription cancellation request ignored as changing PayPal to PayPal, for order ' . $order_id);
}
} else {
WC_Subscriptions_Manager::cancel_subscriptions_for_order($order);
// Subscription Cancellation Completed
$order->add_order_note(__('IPN subscription cancelled for order.', WC_Subscriptions::$text_domain));
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription cancelled for order ' . $order_id);
}
}
break;
case 'subscr_eot':
// Subscription ended, either due to failed payments or expiration
$subscription_length = WC_Subscriptions_Order::get_subscription_length($order);
// PayPal fires the 'subscr_eot' notice immediately if a subscription is only for one billing period, so ignore the request when we only have one billing period
if (1 != $subscription_length && $subscription_length != WC_Subscriptions_Order::get_subscription_interval($order)) {
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription end-of-term for order ' . $order_id);
}
// Record subscription ended
$order->add_order_note(__('IPN subscription end-of-term for order.', WC_Subscriptions::$text_domain));
// Ended due to failed payments so cancel the subscription
if (gmdate('U') + 24 * 60 * 60 < strtotime(WC_Subscriptions_Manager::get_subscription_expiration_date(WC_Subscriptions_Manager::get_subscription_key($order->id), $order->customer_user))) {
WC_Subscriptions_Manager::cancel_subscriptions_for_order($order);
} else {
WC_Subscriptions_Manager::expire_subscriptions_for_order($order);
}
}
break;
case 'subscr_failed':
// Subscription sign up failed
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription payment failure for order ' . $order_id);
}
// Subscription Payment completed
$order->add_order_note(__('IPN subscription payment failure.', WC_Subscriptions::$text_domain));
// First payment on order, don't generate a renewal order
if ($is_first_payment) {
remove_action('processed_subscription_payment_failure', 'WC_Subscriptions_Renewal_Order::generate_failed_payment_renewal_order', 10, 2);
}
WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order_id);
break;
}
// Store the transaction ID to avoid handling requests duplicated by PayPal
if (isset($transaction_details['ipn_track_id'])) {
$handled_ipn_requests[] = $transaction_id;
update_post_meta($order_id, '_paypal_ipn_tracking_ids', $handled_ipn_requests);
}
// Prevent default IPN handling for subscription txn_types
exit;
}
示例2: modify_insert_send_date
/**
* Change the send date of the email for 'before_renewal' and 'before_expire' triggers
* @param array $insert
* @param FUE_Email $email
* @return array
*/
public function modify_insert_send_date($insert, $email)
{
if ($email->type != 'subscription') {
return $insert;
}
$order_id = $insert['order_id'];
$order = WC_FUE_Compatibility::wc_get_order($order_id);
if (!WC_Subscriptions_Order::order_contains_subscription($order)) {
return $insert;
}
$subs_key = WC_Subscriptions_Manager::get_subscription_key($order_id);
if ($email->trigger == 'subs_before_renewal') {
$renewal_date = WC_Subscriptions_Manager::get_next_payment_date($subs_key);
if (!$renewal_date) {
// return false to tell FUE to skip importing this email/order
return false;
}
// convert to local time
$local_renewal_date = get_date_from_gmt($renewal_date, 'U');
$add = FUE_Sending_Scheduler::get_time_to_add($email->interval, $email->duration);
$insert['send_on'] = $local_renewal_date - $add;
} elseif ($email->trigger == 'subs_before_expire') {
$expiry_date = WC_Subscriptions_Manager::get_subscription_expiration_date($subs_key);
if (!$expiry_date) {
return false;
}
// convert to local time
$expiry_timestamp = get_date_from_gmt($expiry_date, 'U');
$add = FUE_Sending_Scheduler::get_time_to_add($email->interval, $email->duration);
$insert['send_on'] = $expiry_timestamp - $add;
}
// Add the subscription key if it is not present in the meta
if (!isset($insert['meta']) || empty($insert['meta']['subs_key'])) {
$insert['meta']['subs_key'] = $subs_key;
}
return $insert;
}
示例3: set_expiration_reminder
public function set_expiration_reminder($user_id, $subs_key)
{
global $wpdb;
$parts = explode('_', $subs_key);
$order_id = $parts[0];
$order = new WC_Order($order_id);
if (WC_Subscriptions_Order::order_contains_subscription($order)) {
// look for renewal emails
$emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}followup_emails WHERE `interval_type` = 'subs_before_expire' AND status = 1");
if (count($emails) > 0) {
$subs = WC_Subscriptions_Manager::get_subscription($subs_key);
$expiry = WC_Subscriptions_Manager::get_subscription_expiration_date($subs_key, $user_id, 'timestamp');
if (0 == $expiry) {
return;
}
foreach ($emails as $email) {
// add this email to the queue
$interval = (int) $email->interval_num;
$add = FUE::get_time_to_add($interval, $email->interval_duration);
$send_on = $expiry - $add;
$insert = array('user_id' => $user_id, 'send_on' => $send_on, 'email_id' => $email->id, 'product_id' => 0, 'order_id' => $order_id);
if ($subs_key) {
$insert['meta']['subs_key'] = $subs_key;
}
FUE::insert_email_order($insert);
}
}
}
}
示例4: set_switch_details_in_cart
/**
* When a subscription switch is added to the cart, store a record of pertinent meta about the switch.
*
* @since 1.4
*/
public static function set_switch_details_in_cart($cart_item_data, $product_id, $variation_id)
{
global $woocommerce;
if (!isset($_GET['switch-subscription'])) {
return $cart_item_data;
}
$subscription = WC_Subscriptions_Manager::get_subscription($_GET['switch-subscription']);
// Requesting a switch for someone elses subscription
if (!WC_Subscriptions_Manager::user_owns_subscription($_GET['switch-subscription'])) {
WC_Subscriptions::add_notice(__('You can not switch this subscription. It appears you do not own the subscription.', 'woocommerce-subscriptions'), 'error');
$woocommerce->cart->empty_cart(true);
wp_redirect(get_permalink($subscription['product_id']));
exit;
}
// Else it's a valid switch
$product = get_product($subscription['product_id']);
$child_products = 0 !== $product->post->post_parent ? get_product($product->post->post_parent)->get_children() : array();
if ($product_id != $subscription['product_id'] && !in_array($subscription['product_id'], $child_products)) {
return $cart_item_data;
}
$next_payment_timestamp = WC_Subscriptions_Manager::get_next_payment_date($_GET['switch-subscription'], get_current_user_id(), 'timestamp');
// If there are no more payments due on the subscription, because we're in the last billing period, we need to use the subscription's expiration date, not next payment date
if (false == $next_payment_timestamp && WC_Subscriptions_Manager::get_subscriptions_completed_payment_count($_GET['switch-subscription']) >= WC_Subscriptions_Order::get_subscription_length($subscription['order_id'], $subscription['product_id'])) {
$next_payment_timestamp = WC_Subscriptions_Manager::get_subscription_expiration_date($_GET['switch-subscription'], get_current_user_id(), 'timestamp');
}
$cart_item_data['subscription_switch'] = array('subscription_key' => $_GET['switch-subscription'], 'next_payment_timestamp' => $next_payment_timestamp, 'upgraded_or_downgraded' => '');
return $cart_item_data;
}
示例5: process_paypal_ipn_request
//.........这里部分代码省略.........
$order = new WC_Order($order_id);
}
if ($order->order_key !== $order_key) {
if (self::$debug) {
self::$log->add('paypal', 'Subscription IPN Error: Order Key does not match invoice.');
}
return;
}
switch ($transaction_details['txn_type']) {
case 'subscr_signup':
// Store PayPal Details
update_post_meta($order_id, 'Payer PayPal address', $transaction_details['payer_email']);
update_post_meta($order_id, 'Payer PayPal first name', $transaction_details['first_name']);
update_post_meta($order_id, 'Payer PayPal last name', $transaction_details['last_name']);
update_post_meta($order_id, 'PayPal Subscriber ID', $transaction_details['subscr_id']);
// Payment completed
$order->add_order_note(__('IPN subscription sign up completed.', WC_Subscriptions::$text_domain));
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription sign up completed for order ' . $order_id);
}
// When there is a free trial & no initial payment amount, we need to mark the order as paid and activate the subscription
if (0 == WC_Subscriptions_Order::get_total_initial_payment($order) && WC_Subscriptions_Order::get_subscription_trial_length($order) > 0) {
$order->payment_complete();
WC_Subscriptions_Manager::activate_subscriptions_for_order($order);
}
break;
case 'subscr_payment':
if ('completed' == strtolower($transaction_details['payment_status'])) {
// Store PayPal Details
update_post_meta($order_id, 'PayPal Transaction ID', $transaction_details['txn_id']);
update_post_meta($order_id, 'Payer PayPal first name', $transaction_details['first_name']);
update_post_meta($order_id, 'Payer PayPal last name', $transaction_details['last_name']);
update_post_meta($order_id, 'PayPal Payment type', $transaction_details['payment_type']);
// Subscription Payment completed
$order->add_order_note(__('IPN subscription payment completed.', WC_Subscriptions::$text_domain));
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription payment completed for order ' . $order_id);
}
$subscriptions_in_order = WC_Subscriptions_Order::get_recurring_items($order);
$subscription_item = array_pop($subscriptions_in_order);
$subscription_key = WC_Subscriptions_Manager::get_subscription_key($order->id, $subscription_item['id']);
$subscription = WC_Subscriptions_Manager::get_subscription($subscription_key, $order->customer_user);
// First payment on order, process payment & activate subscription
if (empty($subscription['completed_payments'])) {
$order->payment_complete();
WC_Subscriptions_Manager::activate_subscriptions_for_order($order);
} else {
WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
}
} elseif ('failed' == strtolower($transaction_details['payment_status'])) {
// Subscription Payment completed
$order->add_order_note(__('IPN subscription payment failed.', WC_Subscriptions::$text_domain));
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription payment failed for order ' . $order_id);
}
WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
} else {
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription payment notification received for order ' . $order_id . ' with status ' . $transaction_details['payment_status']);
}
}
break;
case 'subscr_cancel':
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription cancelled for order ' . $order_id);
}
// Subscription Payment completed
$order->add_order_note(__('IPN subscription cancelled for order.', WC_Subscriptions::$text_domain));
WC_Subscriptions_Manager::cancel_subscriptions_for_order($order);
break;
case 'subscr_eot':
// Subscription ended, either due to failed payments or expiration
// PayPal fires the 'subscr_eot' notice immediately if a subscription is only for one billing period, so ignore the request when we only have one billing period
if (1 != WC_Subscriptions_Order::get_subscription_length($order)) {
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription end-of-term for order ' . $order_id);
}
// Record subscription ended
$order->add_order_note(__('IPN subscription end-of-term for order.', WC_Subscriptions::$text_domain));
// Ended due to failed payments so cancel the subscription
if (time() < strtotime(WC_Subscriptions_Manager::get_subscription_expiration_date(WC_Subscriptions_Manager::get_subscription_key($order->id), $order->customer_user))) {
WC_Subscriptions_Manager::cancel_subscriptions_for_order($order);
} else {
WC_Subscriptions_Manager::expire_subscriptions_for_order($order);
}
}
break;
case 'subscr_failed':
// Subscription sign up failed
if (self::$debug) {
self::$log->add('paypal', 'IPN subscription sign up failure for order ' . $order_id);
}
// Subscription Payment completed
$order->add_order_note(__('IPN subscription sign up failure.', WC_Subscriptions::$text_domain));
WC_Subscriptions_Manager::failed_subscription_sign_ups_for_order($order);
break;
}
// Prevent default IPN handling for subscription txn_types
exit;
}