Using some code snippets plugin we are going to register custom condition in Breakdance. Also you could create small custom plugin and drop this code there.
We are using breakdance_register_template_types_and_conditions action which will run our function called register_edd_purchase_check_condition. That function will register custom condition to check edd_has_user_purchased some product in Easy Digital Downloads.
To change name in Breakdance builder, you can change ‘label’ => ‘{change_me}’ array parameter.
<?php
function register_edd_purchase_check_condition() {
if (!function_exists('\Breakdance\ConditionsAPI\register')) {
return;
}
\Breakdance\ConditionsAPI\register([
'supports' => ['element_display'],
'slug' => 'edd-user-purchase-check',
'label' => 'EDD User Purchase Check',
'category' => 'User Conditions',
'operands' => ['equals', 'not equals'],
// No predefined values; admin inputs the download ID directly
'values' => null, // This allows for a text input in the Breakdance UI
'allowMultiselect' => false,
'callback' => function($operand, $value) {
$user_id = get_current_user_id();
if (!$user_id) {
// If no user is logged in, the condition cannot be met
return false;
}
$download_id = trim($value);
if (!is_numeric($download_id)) {
// If the download ID is not numeric, the condition cannot be properly evaluated
return false;
}
$has_purchased = edd_has_user_purchased($user_id, $download_id);
if ($operand === 'equals' && $has_purchased) {
return true; // User HAS purchased the download
} elseif ($operand === 'not equals' && !$has_purchased) {
return true; // User has NOT purchased the download
}
return false;
},
]);
}
add_action('breakdance_register_template_types_and_conditions', 'register_edd_purchase_check_condition');
We have new conditions called EDD User Purchase Check now inside conditions modal. And we need to equals operator and product ID to check has user purchased particular product.
NOTE: This will just check has user purchased particular product, and alone won’t be enough to check does user have active subscription. For that we need another condition.