本文整理汇总了PHP中WC_Subscriptions_Manager::remove_users_subscription方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::remove_users_subscription方法的具体用法?PHP WC_Subscriptions_Manager::remove_users_subscription怎么用?PHP WC_Subscriptions_Manager::remove_users_subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Manager
的用法示例。
在下文中一共展示了WC_Subscriptions_Manager::remove_users_subscription方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: maybe_manually_change_subscriptions
/**
* When an order is added or updated from the admin interface, check if a new subscription product
* has been manually added to the order, and if one has, create a new subscription.
*
* @param $post_id int The ID of the post which is the WC_Order object.
* @param $post Object The post object of the order.
* @since 1.1
*/
public static function maybe_manually_change_subscriptions($post_id, $post)
{
$order = new WC_Order($post_id);
// Check if all the subscription products on the order have associated subscriptions on the user's account, and if not, add a new one
foreach ($_POST['item_id'] as $item_id) {
if (!WC_Subscriptions_Product::is_subscription($item_id)) {
continue;
}
$subscription_key = WC_Subscriptions_Manager::get_subscription_key($post_id, $item_id);
$subscription = array();
// If order customer changed, move the subscription from the old customer's account to the new customer
if (!empty($order->customer_user) && $order->customer_user != (int) $_POST['customer_user']) {
$subscription = WC_Subscriptions_Manager::remove_users_subscription($order->customer_user, $subscription_key);
$subscriptions = WC_Subscriptions_Manager::get_users_subscriptions((int) $_POST['customer_user']);
if (!empty($subscription)) {
$subscriptions[$subscription_key] = $subscription;
WC_Subscriptions_Manager::update_users_subscriptions((int) $_POST['customer_user'], $subscriptions);
}
}
// In case it's a new order or the customer has changed
$order->customer_user = $order->user_id = (int) $_POST['customer_user'];
$subscription = WC_Subscriptions_Manager::get_users_subscription($order->customer_user, $subscription_key);
if (empty($subscription)) {
// Add a new subscription
// The order doesn't may not exist yet, so we need to set a few things ourselves
$order->order_key = uniqid('order_');
add_post_meta($post_id, '_order_key', $order->order_key, true);
WC_Subscriptions_Manager::create_pending_subscription_for_order($order, $item_id);
// Add the subscription meta for this item to the order
$functions_and_meta = array('get_period' => '_order_subscription_periods', 'get_interval' => '_order_subscription_intervals', 'get_length' => '_order_subscription_lengths');
foreach ($functions_and_meta as $function_name => $meta_key) {
$subscription_meta = self::get_meta($order, $meta_key, array());
$subscription_meta[$item_id] = WC_Subscriptions_Product::$function_name($item_id);
update_post_meta($order->id, $meta_key, $subscription_meta);
}
// Set the subscription's status if it should be something other than pending
switch ($order->status) {
case 'completed':
case 'processing':
WC_Subscriptions_Manager::activate_subscription($order->customer_user, $subscription_key);
break;
case 'refunded':
case 'cancelled':
WC_Subscriptions_Manager::cancel_subscription($order->customer_user, $subscription_key);
break;
case 'failed':
WC_Subscriptions_Manager::failed_subscription_signup($order->customer_user, $subscription_key);
break;
}
}
}
}
示例2: maybe_activate_woocommerce_subscriptions
public static function maybe_activate_woocommerce_subscriptions()
{
global $wpdb;
$is_active = get_option(WC_Subscriptions_Admin::$option_prefix . '_is_active', false);
$active_version = get_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', '0');
if ($is_active == false || version_compare($active_version, self::$version, '<')) {
// Update meta keys for 1.1 to 1.1.1 multisite changes
if (version_compare($active_version, '1.1.1', '<')) {
$updated_count = $wpdb->update($wpdb->usermeta, array('meta_key' => $wpdb->get_blog_prefix() . WC_Subscriptions_Manager::$users_meta_key), array('meta_key' => WC_Subscriptions_Manager::$users_meta_key));
}
// Fix any products that were incorrectly added as a subscription for a user in 1.1.2
if (version_compare($active_version, '1.1.3', '<')) {
foreach (get_users() as $user) {
$users_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($user->ID);
foreach ($users_subscriptions as $subscription_key => $subscription_details) {
if (!isset($subscription_details['order_id'])) {
WC_Subscriptions_Manager::remove_users_subscription($user->ID, $subscription_key);
}
}
}
}
// Add the "Subscriptions" product type if it doesn't exist
if (!get_term_by('slug', sanitize_title(self::$name), 'product_type')) {
wp_insert_term(self::$name, 'product_type');
}
// If no Subscription settings exist, add defaults
if (get_option(WC_Subscriptions_Admin::$option_prefix . '_cancelled_role', false) == false) {
WC_Subscriptions_Admin::add_default_settings();
}
add_option(WC_Subscriptions_Admin::$option_prefix . '_is_active', true);
update_option(WC_Subscriptions_Admin::$option_prefix . '_active_version', self::$version);
set_transient(self::$activation_transient, true, 60 * 60);
do_action('woocommerce_subscriptions_activated');
}
}
示例3: pre_process_shop_order_meta
//.........这里部分代码省略.........
woocommerce_update_order_item_meta($item_id, 'shipping_tax_amount', woocommerce_clean($recurring_order_taxes_shipping_amount[$item_id]));
}
}
} else {
// WC 1.x
if (!isset($_POST['_order_recurring_taxes'])) {
$_POST['_order_recurring_taxes'] = array();
}
foreach ($_POST['_order_recurring_taxes'] as $index => $tax_details) {
if (!isset($tax_details['compound'])) {
$_POST['_order_recurring_taxes'][$index]['compound'] = 0;
}
}
update_post_meta($post_id, '_order_recurring_taxes', $_POST['_order_recurring_taxes']);
}
// Check if all the subscription products on the order have associated subscriptions on the user's account, and if not, add a new one
foreach ($product_ids as $order_item_id => $product_id) {
$is_existing_item = false;
if (in_array($product_id, $existing_product_ids)) {
$is_existing_item = true;
}
// If this is a new item and it's not a subscription product, ignore it
if (!$is_existing_item && !WC_Subscriptions_Product::is_subscription($product_id)) {
continue;
}
// If this is an existing item and it's not a subscription, ignore it
if ($is_existing_item && !WC_Subscriptions_Order::is_item_subscription($order, $product_id)) {
continue;
}
$subscription_key = WC_Subscriptions_Manager::get_subscription_key($post_id, $product_id);
$subscription = array();
// If order customer changed, move the subscription from the old customer's account to the new customer
if (!empty($order->customer_user) && $order->customer_user != (int) $_POST['customer_user']) {
$subscription = WC_Subscriptions_Manager::remove_users_subscription($order->customer_user, $subscription_key);
if (!empty($subscription)) {
$subscriptions = WC_Subscriptions_Manager::get_users_subscriptions((int) $_POST['customer_user']);
$subscriptions[$subscription_key] = $subscription;
WC_Subscriptions_Manager::update_users_subscriptions((int) $_POST['customer_user'], $subscriptions);
}
}
// In case it's a new order or the customer has changed
$order->customer_user = $order->user_id = (int) $_POST['customer_user'];
$subscription = WC_Subscriptions_Manager::get_users_subscription($order->customer_user, $subscription_key);
if (empty($subscription)) {
// Add a new subscription
// The order may not exist yet, so we need to set a few things ourselves
if (empty($order->order_key)) {
$order->order_key = uniqid('order_');
add_post_meta($post_id, '_order_key', $order->order_key, true);
}
if (empty($_POST['order_date'])) {
$start_date = gmdate('Y-m-d H:i:s');
} else {
$start_date = get_gmt_from_date($_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00');
}
WC_Subscriptions_Manager::create_pending_subscription_for_order($order, $product_id, array('start_date' => $start_date));
// Add the subscription meta for this item to the order
$functions_and_meta = array('get_period' => '_order_subscription_periods', 'get_interval' => '_order_subscription_intervals', 'get_length' => '_order_subscription_lengths');
foreach ($functions_and_meta as $function_name => $meta_key) {
$subscription_meta = self::get_meta($order, $meta_key, array());
$subscription_meta[$product_id] = WC_Subscriptions_Product::$function_name($product_id);
update_post_meta($order->id, $meta_key, $subscription_meta);
}
// This works because process_shop_order_item_meta saves item meta to workaround a WC 1.x bug and in WC 2.0+ meta is added when the item is added via Ajax
self::process_shop_order_item_meta($post_id, $post);
// If the order's existing status is something other than pending and the order status is not being changed, manually set the subscription's status (otherwise, it will be handled when WC transitions the order's status)
示例4: upgrade_to_version_1_1_3
/**
* A bug in 1.1.2 was adding products to a users account as a subscription. This fixes that.
*
* @since 1.2
*/
private static function upgrade_to_version_1_1_3()
{
foreach (get_users() as $user) {
$users_subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($user->ID);
foreach ($users_subscriptions as $subscription_key => $subscription_details) {
if (!isset($subscription_details['order_id'])) {
WC_Subscriptions_Manager::remove_users_subscription($user->ID, $subscription_key);
}
}
}
}