コード例 #1
0
 /**
  * A convenience wrapper for changing a users role.
  *
  * @param int $user_id The id of the user whose role should be changed
  * @param string $role_name Either a WordPress role or one of the WCS keys: 'default_subscriber_role' or 'default_cancelled_role'
  * @since 1.0
  * @deprecated 2.0
  */
 public static function update_users_role($user_id, $role_name)
 {
     _deprecated_function(__METHOD__, '2.0', 'wcs_update_users_role()');
     wcs_update_users_role($user_id, $role_name);
 }
コード例 #2
0
 /**
  * When payment is completed, either for the original purchase or a renewal payment, this function processes it.
  *
  * @param $transaction_id string Optional transaction id to store in post meta
  */
 public function payment_complete($transaction_id = '')
 {
     // Make sure the last order's status is updated
     $last_order = $this->get_last_order('all');
     if (false !== $last_order && $last_order->needs_payment()) {
         $last_order->payment_complete($transaction_id);
     }
     // Reset suspension count
     $this->update_suspension_count(0);
     // Make sure subscriber has default role
     wcs_update_users_role($this->get_user_id(), 'default_subscriber_role');
     // Free trial & no-signup fee, no payment received
     if (0 == $this->get_total_initial_payment() && 1 == $this->get_completed_payment_count() && false !== $this->order) {
         if ($this->is_manual()) {
             $note = __('Free trial commenced for subscription.', 'woocommerce-subscriptions');
         } else {
             $note = __('Recurring payment authorized.', 'woocommerce-subscriptions');
         }
     } else {
         $note = __('Payment received.', 'woocommerce-subscriptions');
     }
     $this->add_order_note($note);
     $this->update_status('active');
     do_action('woocommerce_subscription_payment_complete', $this);
     if ($this->get_completed_payment_count() > 1) {
         do_action('woocommerce_subscription_renewal_payment_complete', $this);
     }
 }
コード例 #3
0
/**
 * Give a user the Subscription's default subscriber's inactive role if they do not have an active subscription
 *
 * @since 2.0
 */
function wcs_maybe_make_user_inactive($user_id)
{
    if (!wcs_user_has_subscription($user_id, '', 'active')) {
        wcs_update_users_role($user_id, 'default_inactive_role');
    }
}
コード例 #4
0
 /**
  * When payment is completed, either for the original purchase or a renewal payment, this function processes it.
  *
  * @param $transaction_id string Optional transaction id to store in post meta
  */
 public function payment_complete($transaction_id = '')
 {
     // Make sure the last order's status is updated
     $last_order = $this->get_last_order('all', 'any');
     if (false !== $last_order && $last_order->needs_payment()) {
         $last_order->payment_complete($transaction_id);
     }
     // Reset suspension count
     $this->update_suspension_count(0);
     // Make sure subscriber has default role
     wcs_update_users_role($this->get_user_id(), 'default_subscriber_role');
     // Add order note depending on initial payment
     if (0 == $this->get_total_initial_payment() && 1 == $this->get_completed_payment_count() && false !== $this->order) {
         $note = __('Sign-up complete.', 'woocommerce-subscriptions');
     } else {
         $note = __('Payment received.', 'woocommerce-subscriptions');
     }
     $this->add_order_note($note);
     $this->update_status('active');
     do_action('woocommerce_subscription_payment_complete', $this);
     if (false !== $last_order && wcs_order_contains_renewal($last_order)) {
         do_action('woocommerce_subscription_renewal_payment_complete', $this);
     }
 }