Changing WooCommerce membership status Changing WooCommerce membership status wordpress wordpress

Changing WooCommerce membership status


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

In the database the statuses above look like this:

  • wcm-active
  • wcm-cancelled
  • wcm-complimentary
  • wcm-delayed
  • wcm-expired
  • wcm-paused
  • wcm-pending

All you need to do now is for example this:

$status = 'wcm-paused';$update_args = array( 'ID' => $membership_id, 'post_status' => $status );wp_update_post($update_args);

I hope this helps others.

P.s.: I always prefer using core functions over accessing the database directly. Unlike possible database changes, wp_update_post is a function that is fundamentally used in WordPress and will not disappear in the foreseeable future.


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.


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.