Last active
April 23, 2019 20:43
-
-
Save NickGreen/44e072360b8d1f6d13b50e9a060bbca0 to your computer and use it in GitHub Desktop.
Remove basic membership whenever any other membership plan is purchased
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function remove_basic_membership( $plan, $args ) { | |
// Check that we're purchasing anything other than the basic plan (change number to basic plan id) | |
if ( 123 !== $plan->id ) { | |
$memberships = wc_memberships_get_user_memberships( $args['user_id'] ); | |
foreach ( $memberships as $membership ) { | |
// Check to see if this member has the basic plan | |
// then delete it if so | |
if ( 123 === $membership->plan_id ) { | |
wp_delete_post( $membership->id ); | |
} | |
} | |
} | |
} | |
add_action( 'wc_memberships_grant_membership_access_from_purchase', 'remove_basic_membership', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment