/**
  * trigger function.
  *
  * @access public
  * @return void
  */
 function trigger($subscription)
 {
     $this->object = $subscription;
     if (!is_object($subscription)) {
         _deprecated_argument(__METHOD__, '2.0', 'The subscription key is deprecated. Use a subscription post ID');
         $subscription = wcs_get_subscription_from_key($subscription);
     }
     if (!$this->is_enabled() || !$this->get_recipient()) {
         return;
     }
     update_post_meta($subscription->id, '_cancelled_email_sent', 'true');
     $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
 }
 /**
  * Add a 'new-payment-method' handler to the @see WC_Subscription::can_be_updated_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)
 {
     _deprecated_function(__METHOD__, '2.0', __CLASS__ . '::can_subscription_be_updated_to_new_payment_method()');
     if ('new-payment-method' === $new_status_or_meta) {
         $subscription_can_be_changed = wcs_get_subscription_from_key($args->subscription_key)->can_be_updated_to('new-payment-method');
     }
     return $subscription_can_be_changed;
 }
 /**
  * When a subscription payment hook is fired, reschedule the hook to run again on the
  * time/date of the next payment (if any).
  *
  * WP-Cron's built in wp_schedule_event() function can not be used because the recurrence
  * must be a timestamp, which creates inaccurate schedules for month and year billing periods.
  *
  * @param int $user_id The id of the user who the subscription belongs to
  * @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);
         }
     }
 }
Example #4
0
function sstfg_remove_cap_to_customer($user_id, $subscription_key)
{
    $sub = wcs_get_subscription_from_key($subscription_key);
    $user = new WP_User($user_id);
    $user->remove_cap('access_s2member_level0');
    $user->remove_cap('access_s2member_ccap_sstfg');
}
 /**
  * Check if a given subscription can be renewed.
  *
  * Deprecated because the use of a $subscription_key is deprecated.
  *
  * @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
  * @param int $user_id The ID of the user who owns the subscriptions. Although this parameter is optional, if you have the User ID you should pass it to improve performance.
  * @since 1.2
  * @deprecated 2.0
  */
 public static function can_subscription_be_renewed($subscription_key, $user_id = '')
 {
     _deprecated_function(__METHOD__, '2.0', 'wcs_can_user_resubscribe_to( $subscription, $user_id )');
     return wcs_can_user_resubscribe_to(wcs_get_subscription_from_key($subscription_key), $user_id);
 }
 /**
  * Make sure anything requesting the first payment date for a switched subscription receives a date which
  * takes into account the switch (i.e. prepaid days and possibly a downgrade).
  *
  * This is necessary as the self::calculate_first_payment_date() is not called when the subscription is active
  * (which it isn't until the first payment is completed and the subscription is activated).
  *
  * @deprecated 2.0
  */
 public static function get_first_payment_date($next_payment_date, $subscription_key, $user_id, $type)
 {
     _deprecated_function(__METHOD__, '2.0');
     $subscription = wcs_get_subscription_from_key($subscription_key);
     if ($subscription->has_status('active') && !empty($subscription->order) && wcs_order_contains_switch($subscription->order->id) && 1 >= $subscription->get_completed_payment_count()) {
         $first_payment_timestamp = get_post_meta($subscription->order->id, '_switched_subscription_first_payment_timestamp', true);
         if (0 != $first_payment_timestamp) {
             $next_payment_date = 'mysql' == $type ? date('Y-m-d H:i:s', $first_payment_timestamp) : $first_payment_timestamp;
         }
     }
     return $next_payment_date;
 }
 /**
  * Make sure anything requesting the first payment date for a synced subscription on the front-end receives
  * a date which takes into account the day on which payments should be processed.
  *
  * This is necessary as the self::calculate_first_payment_date() is not called when the subscription is active
  * (which it isn't until the first payment is completed and the subscription is activated).
  *
  * @since 1.5
  * @deprecated 2.0
  */
 public static function get_first_payment_date($first_payment_date, $order, $product_id, $type)
 {
     _deprecated_function(__METHOD__, '2.0');
     $subscription = wcs_get_subscription_from_key($order . '_' . $product_id);
     if (self::order_contains_synced_subscription($order->id) && 1 >= $subscription->get_completed_payment_count()) {
         // Don't prematurely set the first payment date when manually adding a subscription from the admin
         if (!is_admin() || 'active' == $subscription->get_status()) {
             $first_payment_timestamp = self::calculate_first_payment_date($product_id, 'timestamp', $order->order_date);
             if (0 != $first_payment_timestamp) {
                 $first_payment_date = 'mysql' == $type ? date('Y-m-d H:i:s', $first_payment_timestamp) : $first_payment_timestamp;
             }
         }
     }
     return $first_payment_date;
 }
 /**
  * Fire a gateway specific hook when a subscription expires.
  *
  * @since 1.0
  */
 public static function trigger_gateway_subscription_expired_hook($user_id, $subscription_key)
 {
     _deprecated_function(__METHOD__, '2.0', __CLASS__ . '::trigger_gateway_status_updated_hook()');
     self::trigger_gateway_status_updated_hook(wcs_get_subscription_from_key($subscription_key), 'expired');
 }
 /**
  * Obtain subscription by subscriptions < 2.x subscription key without
  * use of deprecated methods when using subscriptions >= 2.x
  * 
  * @param string $subscription_key
  * @return array subscription
  */
 private static function get_subscription_by_subscription_key($subscription_key)
 {
     $subscription = array();
     if (function_exists('wcs_get_subscription_from_key') && function_exists('wcs_get_subscription_in_deprecated_structure')) {
         try {
             $subscription_id = wcs_get_subscription_id_from_key($subscription_key);
             if (null !== $subscription_id && is_numeric($subscription_id)) {
                 if ($subscription = wcs_get_subscription_from_key($subscription_key)) {
                     $subscription = wcs_get_subscription_in_deprecated_structure($subscription);
                 }
             }
         } catch (Exception $e) {
             $subscription = array();
         }
     } else {
         $subscription = WC_Subscriptions_Manager::get_subscription($subscription_key);
     }
     return $subscription;
 }