Changing membership status in woocommerce

woocommerce memberships functions
woocommerce memberships demo
woocommerce membership role
membership plans woocommerce
woocommerce memberships download
woocommerce memberships developer documentation
woocommerce member pricing
woocommerce subscriptions

I've been banging my head for about a week now. any help would be greatly appreciated.

I have a woocommerce store where I need to be able to update the user's membership status (cancelled, active, etc etc) through Php.

I know I can grab their current status with:

wc_memberships_get_user_membership( $user_id, $membership_id );

and create new memberships with:

wc_memberships_create_user_membership( $args );

but I haven't found a way to just change the status.

thanks!

WooCommerce Memberships Admin Hook Reference , For anyone else coming here. Here is my preferred solution. A WooCommerce Membership is just another WordPress post in your database  For anyone else coming here. Here is my preferred solution. A WooCommerce Membership is just another WordPress post in your database and the membership status is stored as the post status. WooCommerce Memberships comes with the following statuses by default: Active; Cancelled; Complimentary; Delayed; Expired; Paused; Pending Cancellation

Alright, so after searching around for more than a month, and going back and forth with Woocommerce's support team (they were no help :/ ), I came up with this solution:

Swimming around in the database I noticed that all memberships are just posts, and they have an ID and a post author. so I figured I could write up a little SQL to make it work.

using WordPres's built-in $wpdb class I was able to just update the field directly in the database:

first you have to include $wpdb in your function:

            global $wpdb;

then you put the query together, below is what it looks like in regular SQL

        UPDATE ie_posts
        SET post_status ='wcm-active'
        WHERE post_parent = 49 AND post_author = 49870

And here's what is looks like using the class:

        $wpdb->update('ie_posts',
            array('post_status' => $_status),
            array('post_parent' => $_membership_id,
                  'post_author' => $_user_id)
        );

I would advise trying this using a development copy of your database so you don't break anything.

deff not the prettiest way of doing it, but it works like a charm. if anyone has a better way of taking care of it, please let me know.

WooCommerce Memberships FAQ, WooCommerce Memberships comes with the following statuses by default: Active; Cancelled; Complimentary; Delayed; Expired; Paused; Pending Cancellation. In  For anyone else coming here. Here is my preferred solution. A WooCommerce Membership is just another WordPress post in your database and the membership status is stored as the post status. WooCommerce Memberships comes with the following statuses by default: Active; Cancelled; Complimentary; Delayed; Expired; Paused; Pending Cancellation

I'll try this way, for example to get any membership with a 'pending' status:

$user_id = get_current_user_id();

$args = array( 
    'status' => 'pending'
); 

$pending_memberships = wc_memberships_get_user_memberships( $user_id, $args );

Then and with a conditional check, you should be able to change this pending status to another one.

WooCommerce Memberships Subscriptions Integration , Change WooCommerce Memberships Status Name. Let's keep things simple for now and try to change the Active status label for example. Unlimited memberships – The membership status will listen to subscription status until the subscription ends, after which it will stay active indefinitely. Subscription-tied memberships – The membership statuses become tied to the subscription’s statuses. This allows you or your customers to change the subscription status and thus trigger a change in the membership.

Changing WooCommerce membership status, You don't like this heading and would like to change it into “Exclusive Discounts” instead. If you just want WooCommerce Memberships change discount heading WooCommerce Order Status Manager Version 1.3 · Next  Subscription Switching Guide Customers can upgrade and downgrade their subscriptions, using the WooCommerce Subscriptions switching feature. We recommend reading the Store Manager Guide to get a more general introduction to working with the Subscriptions extension.

Changing membership status in woocommerce, Dynamically change user role with membership status. Memberships provides built-in perks for members, which can let you provide discounts or VIP content for​  Go to WooCommerce > Settings > General, and scroll down to Order Status Control; Choose from All Orders to change the order status to “completed” after successful payment for all orders, Virtual Orders to change the order status only for orders that contain all virtual products, or None to stop auto-completion all together. That’s it!

WooCommerce Memberships – Get Plan Statuses, Any time a membership changes from one status to another, you can run a workflow to trigger emails, update the membership, or take other  WooCommerce Order Status Manager allows you to create extra order statuses you need, create a “next status” flow so that you can add action buttons to your orders page, add icons and bulk actions, and even tie emails to these new statuses to completely support your fulfillment workflow.

Comments
  • You want to change the status for all users? and immediately?
  • no, I need to change the status for one user on one membership
  • ok, cool. how do you go about changing it though? that's the part I'm stuck in. let's say a user has 2 memberships, and I need to modify the status of one.
  • I have the same problem, can't find command for modifying the status...any update?
  • @Stephen yes, see my answer. it's dirty, but it works