Last active
November 3, 2025 13:28
-
-
Save kimwhite/c48d7f8d5c4a6a11da4904beade72cae to your computer and use it in GitHub Desktop.
Add Gift Aid note to recurring orders if user has opted in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php // do not copy this line. | |
| /** | |
| * This recipe Adds Gift Aid note to recurring orders if user has opted in. | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. | |
| * Read this companion article for step-by-step directions on either method. | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function pmproga_add_gift_aid_to_recurring_orders( $order ) { | |
| if ( empty( $order ) || empty( $order->user_id ) ) { | |
| return; | |
| } | |
| // Check user's stored Gift Aid preference. | |
| $gift_aid = get_user_meta( $order->user_id, 'gift_aid', true ); | |
| // Only append if not already in notes. | |
| if ( strpos( $order->notes, 'Gift Aid:' ) === false ) { | |
| if ( $gift_aid == 1 ) { | |
| $order->notes .= "Gift Aid: Yes\n"; | |
| } else { | |
| $order->notes .= "Gift Aid: No\n"; | |
| } | |
| $order->saveOrder(); | |
| } | |
| } | |
| add_action( 'pmpro_added_order', 'pmproga_add_gift_aid_to_recurring_orders' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment