Last active
August 29, 2015 14:19
-
-
Save mattallan/72432317141c782213f4 to your computer and use it in GitHub Desktop.
Limit Subscriptions to one active/suspended per user.
This file contains hidden or 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 | |
/** | |
* Plugin Name: User Limited Subscriptions | |
* Description: Limit users to only one active or suspended subscription | |
* Author: Matt Allan | |
* Author URI: http://www.prospress.com | |
* Version: 1.0 | |
* License: GPL v2 | |
*/ | |
/** | |
* Limit customers to one active or suspended subscription. Once they cancell their subscription | |
* or the subscriptions expires, they will then be able to purchase another. | |
* | |
* @param bool $purchasable | |
* @param WC_Product_Subscription|WC_Product_Variable_Subscription $product | |
* @author [email protected] | |
*/ | |
function mc_one_subscription_per_customer( $purchasable, $product ) { | |
$user = wp_get_current_user(); | |
if( in_array( get_option( WC_Subscriptions_Admin::$option_prefix . '_subscriber_role' ), $user->roles ) ) { | |
$purchasable = false; | |
} | |
return $purchasable; | |
} | |
add_filter( 'woocommerce_subscription_is_purchasable', 'mc_one_subscription_per_customer', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment