Skip to content

Instantly share code, notes, and snippets.

@Spellhammer
Created December 22, 2020 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Spellhammer/a5be07c478eabb11aa7fb604d601b2a7 to your computer and use it in GitHub Desktop.
Save Spellhammer/a5be07c478eabb11aa7fb604d601b2a7 to your computer and use it in GitHub Desktop.
EDD Conditions
if( function_exists('oxygen_vsb_register_condition') ) {
oxygen_vsb_register_condition('User...', array('options'=>array(), 'custom'=>true), array('has purchased', 'has not purchased'), 'ex_edd_has_user_purchased_callback', 'EDD');
function ex_edd_has_user_purchased_callback($value, $operator) {
$current_user = get_current_user_id();
$value = intval($value);
if( $operator == 'has purchased' ) {
if( edd_has_user_purchased($current_user, $value) ) {
return true;
} else {
return false;
}
} else if( $operator == 'has not purchased' ) {
if( !edd_has_user_purchased($current_user, $value) ) {
return true;
} else {
return false;
}
}
}
oxygen_vsb_register_condition('User is...', array('options'=>array(), 'custom'=>true), array('subscribed to', 'not subscribed to'), 'ex_edd_has_active_subscription_callback', 'EDD');
function ex_edd_has_active_subscription_callback($value, $operator) {
$subscriber = new EDD_recurring_subscriber( get_current_user_id() );
$value = intval($value);
if( $operator == 'subscribed to' ) {
if( $subscriber->get_subscriptions( $value, array( 'active' ) ) ) {
return true;
} else {
return false;
}
} else if( $operator == 'not subscribed to' ) {
if( !$subscriber->get_subscriptions( $value, array( 'active' ) ) ) {
return true;
} else {
return false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment