Filter
uncanny-automator
automator_charitable_recipe_default_amount
Filters the default donation amount used in Charitable campaigns when this integration is active.
add_filter( 'automator_charitable_recipe_default_amount', $callback, 10, 1 );
Description
Filters the default donation amount for Charitable integrations. Developers can use this hook to programmatically set a different default donation amount displayed in recipe fields for Charitable donations. The default value is 100.
Usage
add_filter( 'automator_charitable_recipe_default_amount', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Set a custom default donation amount for the Charitable integration recipe.
*
* This function hooks into the 'automator_charitable_recipe_default_amount' filter
* to override the default donation amount of 100 set in the plugin.
*
* @param mixed $default_amount The current default donation amount.
* @return int The new default donation amount.
*/
function my_custom_charitable_default_donation_amount( $default_amount ) {
// Let's set a custom default donation amount of 50.
$custom_amount = 50;
// Ensure the custom amount is an integer.
return (int) $custom_amount;
}
add_filter( 'automator_charitable_recipe_default_amount', 'my_custom_charitable_default_donation_amount', 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/charitable/helpers/charitable-helpers.php:91
public function donation_amount_input() {
$default_amount = (int) apply_filters( 'automator_charitable_recipe_default_amount', 100 );
return Automator()->helpers->recipe->field->int(
array(
'option_code' => 'DONATION_AMOUNT',
'label' => esc_attr__( 'Amount', 'uncanny-automator' ),
'placeholder' => sprintf(
/* translators: 1: Default amount */
esc_attr__( 'Example: %d', 'uncanny-automator' ),
$default_amount
),
'default' => $default_amount,
'min_number' => 1, //REVIEW - possible to grab the min donation amount from the selected campaign?
)
);
}