Filter
uncanny-automator
automator_mepr_check_first_real_payment
Filters if the current MemberPress payment is the member's first real payment, allowing for custom logic.
add_filter( 'automator_mepr_check_first_real_payment', $callback, 10, 1 );
Description
Filters whether a MemberPress recurring subscription purchase should be considered the first actual payment. Developers can return `true` to force the trigger to recognize it as the first payment, bypassing renewal checks. This is useful for specific automation scenarios requiring initial payment recognition.
Usage
add_filter( 'automator_mepr_check_first_real_payment', 'your_function_name', 10, 1 );
Parameters
-
$event(mixed) - This parameter is the return value of the filter, and when `true`, it signifies that the trigger should proceed with checking for the first real payment.
Return Value
The filtered value.
Examples
/**
* Example of the automator_mepr_check_first_real_payment filter.
*
* This filter allows you to override the default logic for determining if a
* MemberPress transaction is the first real payment (not a free trial or setup fee)
* for a recurring subscription.
*
* In this example, we'll specifically allow a payment if the payment method
* is 'stripe' and it's not the first real payment, effectively letting the trigger
* run for renewals even if the default logic would prevent it.
*
* @param bool $default_behavior The default return value of the filter. False means the trigger will run.
* @param array $event The event object passed to the filter.
*
* @return bool True to prevent the trigger from running, false to allow it.
*/
add_filter( 'automator_mepr_check_first_real_payment', function( $default_behavior, $event ) {
// Ensure we have the necessary data from the event.
if ( ! isset( $event['transaction'] ) || ! $event['transaction'] instanceof MeprTransaction ) {
return $default_behavior; // Return default if transaction data is missing.
}
$transaction = $event['transaction'];
$payment_method_id = $transaction->payment_method();
// Example: Allow the trigger to run for Stripe payments that are NOT the first real payment.
// This overrides the default behavior of preventing the trigger for renewals.
if ( 'stripe' === $payment_method_id && ! MeprTransaction::$free_gateway_str !== $payment_method_id ) {
// If it's a Stripe payment and not a free gateway, we want the trigger to proceed,
// so we return false to indicate that the check for "first real payment" should not prevent it.
return false;
}
// For all other scenarios, stick to the default behavior determined by the original filter.
return $default_behavior;
}, 10, 2 );
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/memberpress/triggers/mp-purchaseproductrecurring.php:103
}
// Flexibility to prevent running the trigger.
if ( ! apply_filters( 'automator_mepr_recurring_subscriptions_trigger_switch', true, $event ) ) {
return;
}
if ( apply_filters( 'automator_mepr_check_first_real_payment', false, $event ) ) {
$subscription = $transaction->subscription();
$is_first_real_payment = Automator()->helpers->recipe->memberpress->check_if_is_renewal_or_first_payment( $subscription );
$pm = $transaction->payment_method();
if ( $is_first_real_payment === false && MeprTransaction::$free_gateway_str !== $pm->id ) {
return;
}
}