How to Enable WPCodeBox Dark Mode in A...
Optimize your admin experience with WPCodeBox Dark Mode. Download this snippet to eas...

WPCodeBox
293

This snippet provides Oxygen Builder conditions for Easy Digital Downloads, allowing you to gate content based on user purchases and subscriptions, including “User Has Purchased,” “User Has Not Purchased,” “User Is Subscribed To,” and “User Is Not Subscribed To” a specific download ID.
<?php
add_action('plugins_loaded', function () {
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;
}
}
}
}
});





