Action uncanny-automator

uap-event-renewal-transaction-completed

Fires after a member renewal transaction is successfully completed within MemberPress, providing transaction details.

add_action( 'uap-event-renewal-transaction-completed', $callback, 10, 1 );

Description

Fires after a MemberPress recurring subscription renewal transaction is successfully completed. Developers can hook into this action to perform custom actions, such as sending notifications, updating user meta, or triggering other workflows, passing the transaction details as an argument. This hook is triggered internally by the User Automator plugin's MemberPress integration.


Usage

add_action( 'uap-event-renewal-transaction-completed', 'your_function_name', 10, 1 );

Parameters

$args (mixed)
This parameter contains an array of arguments related to the completed renewal transaction.

Examples

/**
 * Example function to hook into the 'uap-event-renewal-transaction-completed' action.
 * This function will be executed whenever a renewal transaction is completed within the Ultimate Addons for
 * MemberPress (UAP) plugin, and specifically when the MemberPress 'mepr-event-renewal-transaction-completed'
 * action has fired and subsequently triggered the UAP hook.
 *
 * The $args parameter is expected to contain details about the completed renewal transaction.
 * We'll assume it's an array and try to extract specific information.
 *
 * @param mixed $args The arguments passed from the 'uap-event-renewal-transaction-completed' hook.
 */
add_action( 'uap-event-renewal-transaction-completed', function( $args ) {

	// Check if $args is an array and contains expected keys for demonstration.
	if ( is_array( $args ) && isset( $args['transaction_id'] ) && isset( $args['user_id'] ) ) {

		$transaction_id = $args['transaction_id'];
		$user_id        = $args['user_id'];
		$user           = get_user_by( 'id', $user_id );

		// Log a message indicating the renewal completion.
		// In a real-world scenario, you might update user meta, send an email,
		// trigger another automation, etc.
		if ( $user ) {
			error_log( sprintf(
				'UAP Renewal Transaction Completed: Transaction ID %d for User "%s" (ID: %d).',
				$transaction_id,
				$user->user_login,
				$user_id
			) );

			// Example: If the renewal is for a specific membership level, you might perform
			// a different action. Let's assume $args['membership_id'] might exist.
			if ( isset( $args['membership_id'] ) ) {
				$membership_id = $args['membership_id'];
				error_log( sprintf(
					'Membership ID for renewal: %d.',
					$membership_id
				) );
				// Further logic based on membership_id can be added here.
			}
		} else {
			error_log( sprintf(
				'UAP Renewal Transaction Completed: Transaction ID %d for unknown User ID %d.',
				$transaction_id,
				$user_id
			) );
		}
	} else {
		// Handle cases where $args is not in the expected format.
		error_log( 'UAP Renewal Transaction Completed: Received unexpected arguments format.' );
		error_log( print_r( $args, true ) ); // Log the raw args for debugging.
	}

}, 10, 1 ); // Priority 10, accepts 1 argument.

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-renews-recurring-subscription.php:30

public function setup_trigger() {

		add_action(
			'mepr-event-renewal-transaction-completed',
			function( $args ) {
				do_action( 'uap-event-renewal-transaction-completed', $args );
			}
		);

		$this->add_action( 'uap-event-renewal-transaction-completed', 99, 1 );

		$this->set_integration( 'MP' );
		$this->set_trigger_code( 'MP_RENEW_SUBSCRIPTION' );
		$this->set_trigger_meta( 'MPPRODUCT' );
		//$this->set_is_pro( true );
		$this->set_support_link( Automator()->get_author_support_link( $this->get_trigger_code(), 'integration/memberpress/' ) );
		$this->set_sentence(
		/* Translators: Trigger sentence - Memberpress */
			sprintf( esc_html__( 'A user renews {{a recurring subscription product:%1$s}}', 'uncanny-automator' ), $this->get_trigger_meta() )
		);
		// Non-active state sentence to show
		$this->set_readable_sentence( esc_attr__( 'A user renews {{a recurring subscription product}}', 'uncanny-automator' ) );
		// Which do_action() fires this trigger.
		$this->add_action( 'uap-event-renewal-transaction-completed', 999, 1 );
		$this->set_options_callback( array( $this, 'load_options' ) );
		$this->register_trigger();

	}

Scroll to Top