本文整理汇总了PHP中WC_Subscriptions_Manager::reactivate_subscription方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::reactivate_subscription方法的具体用法?PHP WC_Subscriptions_Manager::reactivate_subscription怎么用?PHP WC_Subscriptions_Manager::reactivate_subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Manager
的用法示例。
在下文中一共展示了WC_Subscriptions_Manager::reactivate_subscription方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process_actions
/**
* Handle activate & cancel actions for both individual items and bulk edit.
*
* @since 1.0
*/
public function process_actions()
{
$custom_actions = apply_filters('woocommerce_subscriptions_list_table_pre_process_actions', array('custom_action' => false, 'messages' => array(), 'error_messages' => array()));
if ($this->current_action() === false && $custom_actions['custom_action'] === false) {
return;
}
$messages = array();
$error_messages = array();
$query_args = array();
// Check if custom actions were taken by the filter - if so, it has handled the action and we only need to set the message/error messages
if ($custom_actions['custom_action'] !== false) {
$messages = $custom_actions['messages'];
$error_messages = $custom_actions['error_messages'];
} else {
if (isset($_GET['subscription'])) {
// Single subscription action
if (!wp_verify_nonce($_REQUEST['_wpnonce'], $_GET['subscription'])) {
wp_die(__('Action failed. Invalid Nonce.', WC_Subscriptions::$text_domain));
}
if (!WC_Subscriptions_Manager::can_subscription_be_changed_to($_GET['new_status'], $_GET['subscription'], $_GET['user'])) {
$error_messages[] = sprintf(__('Error: Subscription status can not be changed to "%s".', WC_Subscriptions::$text_domain), esc_html($_GET['new_status']));
} else {
switch ($_GET['new_status']) {
case 'active':
WC_Subscriptions_Manager::reactivate_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription activated.', WC_Subscriptions::$text_domain);
break;
case 'on-hold':
WC_Subscriptions_Manager::put_subscription_on_hold($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription put on-hold.', WC_Subscriptions::$text_domain);
break;
case 'cancelled':
WC_Subscriptions_Manager::cancel_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription cancelled.', WC_Subscriptions::$text_domain);
break;
case 'trash':
WC_Subscriptions_Manager::trash_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription trashed.', WC_Subscriptions::$text_domain);
break;
case 'deleted':
WC_Subscriptions_Manager::delete_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription deleted.', WC_Subscriptions::$text_domain);
break;
default:
$error_messages[] = __('Error: Unknown subscription status.', WC_Subscriptions::$text_domain);
break;
}
}
} else {
if (isset($_GET['subscription_keys'])) {
// Bulk actions
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-' . $this->_args['plural'])) {
wp_die(__('Bulk edit failed. Invalid Nonce.', WC_Subscriptions::$text_domain));
}
$subscriptions = $_GET['subscription_keys'];
$subscription_count = 0;
$error_count = 0;
if (in_array($this->current_action(), array('trash', 'deleted'))) {
foreach ($subscriptions as $user_id => $subscription_keys) {
foreach ($subscription_keys as $subscription_key) {
if (!WC_Subscriptions_Manager::can_subscription_be_changed_to($this->current_action(), $subscription_key, $user_id)) {
$error_count++;
} else {
$subscription_count++;
if ('trash' == $this->current_action()) {
WC_Subscriptions_Manager::trash_subscription($user_id, $subscription_key);
} else {
WC_Subscriptions_Manager::delete_subscription($user_id, $subscription_key);
}
}
}
}
if ($subscription_count > 0) {
if ('trash' == $this->current_action()) {
$messages[] = sprintf(_n('%d subscription moved to trash.', '%s subscriptions moved to trash.', $subscription_count, WC_Subscriptions::$text_domain), $subscription_count);
} else {
$messages[] = sprintf(_n('%d subscription deleted.', '%s subscriptions deleted.', $subscription_count, WC_Subscriptions::$text_domain), $subscription_count);
}
}
if ($error_count > 0) {
if ('trash' == $this->current_action()) {
$error_messages[] = sprintf(_n('%d subscription could not be trashed - is it active or on-hold? Try cancelling it before trashing it.', '%s subscriptions could not be trashed - are they active or on-hold? Try cancelling them before trashing.', $error_count, WC_Subscriptions::$text_domain), $error_count);
} else {
$error_messages[] = sprintf(_n('%d subscription could not deleted - is it active or on-hold? Try cancelling it before deleting.', '%s subscriptions could not deleted - are they active or on-hold? Try cancelling them before deleting.', $error_count, WC_Subscriptions::$text_domain), $error_count);
}
}
}
}
}
}
$message_nonce = wp_create_nonce(__FILE__);
set_transient($this->message_transient_prefix . $message_nonce, array('messages' => $messages, 'error_messages' => $error_messages), 60 * 60);
// Filter by a given customer or product?
if (isset($_GET['_customer_user']) || isset($_GET['_product_id'])) {
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-subscriptions')) {
//.........这里部分代码省略.........
示例2: process_actions
/**
* Handle activate & cancel actions for both individual items and bulk edit.
*
* @since 1.0
*/
public function process_actions()
{
if ($this->current_action() === false) {
return;
}
$messages = array();
$error_messages = array();
// Single subscription action
if (isset($_GET['subscription'])) {
if (!wp_verify_nonce($_REQUEST['_wpnonce'], $_GET['subscription'])) {
wp_die(__('Action failed. Invalid Nonce.', WC_Subscriptions::$text_domain));
}
if (!WC_Subscriptions_Manager::can_subscription_be_changed_to($_GET['new_status'], $_GET['subscription'], $_GET['user'])) {
$error_messages[] = sprintf(__('Error: Subscription status can not be changed to "%s".', WC_Subscriptions::$text_domain), esc_html($_GET['new_status']));
} else {
switch ($_GET['new_status']) {
case 'active':
WC_Subscriptions_Manager::reactivate_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription activated.', WC_Subscriptions::$text_domain);
break;
case 'suspended':
WC_Subscriptions_Manager::suspend_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription suspended.', WC_Subscriptions::$text_domain);
break;
case 'cancelled':
WC_Subscriptions_Manager::cancel_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription cancelled.', WC_Subscriptions::$text_domain);
break;
case 'trash':
WC_Subscriptions_Manager::trash_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription trashed.', WC_Subscriptions::$text_domain);
break;
default:
$error_messages[] = __('Error: Unknown subscription status.', WC_Subscriptions::$text_domain);
break;
}
}
} else {
if (isset($_GET['subscriptions'])) {
// Bulk actions
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-' . $this->_args['plural'])) {
wp_die(__('Bulk edit failed. Invalid Nonce.', WC_Subscriptions::$text_domain));
}
$subscriptions = $_GET[$this->_args['plural']];
$subscription_count = 0;
$error_count = 0;
if ('trash' === $this->current_action()) {
foreach ($subscriptions as $user_id => $subscription_keys) {
foreach ($subscription_keys as $subscription_key) {
if (!WC_Subscriptions_Manager::can_subscription_be_changed_to('trash', $subscription_key, $user_id)) {
$error_count++;
} else {
$subscription_count++;
WC_Subscriptions_Manager::trash_subscription($user_id, $subscription_key);
}
}
}
if ($subscription_count > 0) {
$messages[] = sprintf(_n('%d subscription moved to trash.', '%s subscriptions moved to trash.', $subscription_count), $subscription_count);
}
if ($error_count > 0) {
$error_messages[] = sprintf(_n('%d subscription could not be trashed - is it active or suspended? Try cancelling it before trashing it.', '%s subscriptions could not be trashed - are they active or suspended? Try cancelling them before trashing.', $error_count), $error_count);
}
}
}
}
$status = isset($_GET['status']) ? $_GET['status'] : 'all';
$message_nonce = wp_create_nonce(__FILE__);
set_transient($this->message_transient_prefix . $message_nonce, array('messages' => $messages, 'error_messages' => $error_messages), 60 * 60);
$redirect_to = add_query_arg(array('status' => $status, 'message' => $message_nonce), admin_url('admin.php?page=subscriptions'));
// Redirect to avoid performning actions on a page refresh
wp_safe_redirect($redirect_to);
}
示例3: process_subscription_payment_on_child_order
/**
* If the payment for a renewal order has previously failed and is then paid, we need to make sure the
* subscription payment function is called.
*
* @param int $user_id The id of the user who purchased the subscription
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
* @since 1.2
*/
public static function process_subscription_payment_on_child_order($order_id, $payment_status = 'completed')
{
if (self::is_renewal($order_id, array('order_role' => 'child'))) {
$child_order = new WC_Order($order_id);
$parent_order = self::get_parent_order($child_order);
$subscriptions_in_order = $child_order->get_items();
// Should only be one subscription in the renewal order, but just in case
foreach ($subscriptions_in_order as $item) {
$item_id = WC_Subscriptions_Order::get_items_product_id($item);
if (WC_Subscriptions_Order::is_item_subscription($parent_order, $item_id)) {
if ('failed' == $payment_status) {
// Don't duplicate renewal order
remove_action('processed_subscription_payment_failure', __CLASS__ . '::generate_failed_payment_renewal_order', 10, 2);
WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($parent_order->id, $item_id);
// But make sure orders are still generated for other payments in the same request
add_action('processed_subscription_payment_failure', __CLASS__ . '::generate_failed_payment_renewal_order', 10, 2);
} else {
// Don't duplicate renewal order
remove_action('processed_subscription_payment', __CLASS__ . '::generate_paid_renewal_order', 10, 2);
WC_Subscriptions_Manager::process_subscription_payments_on_order($parent_order->id, $item_id);
// But make sure orders are still generated for other payments in the same request
add_action('processed_subscription_payment', __CLASS__ . '::generate_paid_renewal_order', 10, 2);
// Reactivate the subscription - activate_subscription doesn't operate on child orders
$subscription_key = WC_Subscriptions_Manager::get_subscription_key($parent_order->id, $item_id);
WC_Subscriptions_Manager::reactivate_subscription($parent_order->customer_user, $subscription_key);
}
}
}
}
}
示例4: putSubscriptionON_action
function putSubscriptionON_action()
{
$action = $_REQUEST['user_action'];
$userID = get_current_user_id();
$cur_user_subscription = get_user_meta($userID, 'wp_woocommerce_subscriptions', true);
foreach ($cur_user_subscription as $suk => $suv) {
$subscriptionID = $suv['order_id'] . '_' . $suv['product_id'];
}
$wsm = new WC_Subscriptions_Manager();
if ($action == 'pause') {
$wsm->put_subscription_on_hold($userID, $subscriptionID);
update_user_meta($userID, 'permanent_pause', 'active');
} else {
if ($action == 'resume') {
$nxtTues = date_i18n('Ymd', strtotime('next tuesday'));
$currDate = date_i18n('Ymd');
if ($currDate + 6 > $nxtTues) {
$nxtTues = $nxtTues + 7;
}
delete_user_meta($userID, 'suspended', $nxtTues);
$wsm->reactivate_subscription($userID, $subscriptionID);
delete_user_meta($userID, 'permanent_pause', 'active');
}
}
echo '-1';
exit;
}