For developers who need to go beyond the level settings, the Gift Membership Add On offers one action hook, one filter hook, and two global variables. Use them to run your own code after a gift purchase, change how gift codes are created, or set up gift levels in PHP.
Actions
pmprogl_gift_code_purchased
Fires after a gift code is created for a completed gift purchase. The code, the giver’s list of purchased codes, and the order’s gift details are already saved. The gift emails are sent right after this action runs. Use it to sync the purchase to a CRM, log it, or notify someone else.
For orders paid by check or another offline method, this action fires when the order is marked as paid.
do_action( 'pmprogl_gift_code_purchased', int $code_id, int $user_id, int $order_id );
Parameters
$code_id: int; The ID of the new gift code in the discount codes table.$user_id: int; The ID of the member who bought the gift.$order_id: int; The ID of the gift order.
Example
function my_pmprogl_gift_code_purchased( $code_id, $user_id, $order_id ) {
// Count how many gifts this member has bought.
$gift_count = (int) get_user_meta( $user_id, 'my_gift_purchase_count', true );
update_user_meta( $user_id, 'my_gift_purchase_count', $gift_count + 1 );
}
add_action( 'pmprogl_gift_code_purchased', 'my_pmprogl_gift_code_purchased', 10, 3 );
Filters
pmprogl_gift_code_settings
Filters the settings for a new gift code before it’s saved. Use this to change how long recipients have to redeem a gift, allow a code to be used more than once, or change the code format.
apply_filters( 'pmprogl_gift_code_settings', array $gift_code_settings );
Parameters
$gift_code_settings: array; The gift code settings, with these keys:code: string; The code. Default isGfollowed by a random string. Codes must be unique.starts: string; The start date inY-m-dformat. Default is yesterday, so the code works right away.expires: string; The expiration date inY-m-dformat. Default is one year from today.uses: int; How many times the code can be used. Default1.
Example
function my_pmprogl_gift_code_settings( $gift_code_settings ) {
// Give recipients two years to redeem their gift.
$gift_code_settings['expires'] = date( 'Y-m-d', strtotime( '+2 years' ) );
return $gift_code_settings;
}
add_filter( 'pmprogl_gift_code_settings', 'my_pmprogl_gift_code_settings' );
Set Up Gift Levels With Custom Code
Most sites should set up gift levels on the Edit Membership Level screen. Two global variables are still available for sites that need more control, such as charging the recipient a price when they redeem their gift. Set them in a customizations plugin at the top level of the file, so they’re defined before WordPress runs the init action.
$pmprogl_gift_levels
An array of gift levels. Each key is the ID of a gift level (the level the giver checks out for). Each value is an array describing the code the giver gets: which level the recipient receives and the pricing and expiration that apply when they redeem it.
| Key | Description |
|---|---|
level_id | The ID of the level the recipient gets when they redeem the code. |
initial_payment | The amount the recipient pays at checkout when they redeem the code. Use 0 for a free gift. |
billing_amount | The recurring amount the recipient pays after checkout. Use 0 for no subscription. |
cycle_number | The number of cycle periods between recurring payments. |
cycle_period | The billing cycle period: Day, Week, Month, or Year. |
billing_limit | The number of recurring payments to charge. Use 0 for no limit. |
trial_amount | The amount of each trial payment. |
trial_limit | The number of recurring payments charged at the trial amount. |
expiration_number | The number of expiration periods until the recipient’s membership ends. Use 0 for a membership that never expires. |
expiration_period | The expiration period: Day, Week, Month, or Year. |
$pmprogl_require_gift_code
An array of level IDs that can only be joined with a discount code. Checkout for these levels without a code stops with the message “You must use a valid discount code to register for this level.” Any valid discount code for the level is accepted, not only gift codes.
Without custom code, you can get a similar result by checking Disable New Signups on the gifted level. See What the Recipient Gets.
Example
This example makes level 11 a gift level that gives the recipient level 2 free for six months. It also makes level 3 a gift level whose code charges the recipient $10 at checkout and then $10 per month for 12 more payments for level 4, and requires a discount code to join level 4.
global $pmprogl_gift_levels, $pmprogl_require_gift_code;
$pmprogl_gift_levels = array(
// Gift level 11: the recipient gets level 2 free for 6 months.
11 => array(
'level_id' => 2,
'initial_payment' => 0,
'billing_amount' => 0,
'cycle_number' => 0,
'cycle_period' => '',
'billing_limit' => 0,
'trial_amount' => 0,
'trial_limit' => 0,
'expiration_number' => 6,
'expiration_period' => 'Month',
),
// Gift level 3: the recipient pays $10 now, then $10 per month for 12 payments, for level 4.
3 => array(
'level_id' => 4,
'initial_payment' => 10,
'billing_amount' => 10,
'cycle_number' => 1,
'cycle_period' => 'Month',
'billing_limit' => 12,
'trial_amount' => 0,
'trial_limit' => 0,
'expiration_number' => 0,
'expiration_period' => '',
),
);
// Level 4 can only be joined with a discount code.
$pmprogl_require_gift_code = array( 4 );
We also have a sample setup file on GitHub with more comments.
Allow Gift Emails With Custom Code
The Gift Code section at checkout still depends on the Allow Gift Emails setting saved on each gift level. To turn it on for a level you set up in code:
- Edit the gift level and check Gift Level? to show the Gift Membership settings.
- Check Allow Gift Emails.
- Uncheck Gift Level? and click Save Level.
Get Support From Our Team of Experts
Have a question about how to use this feature? Our Support Page outlines three ways to get support.
Our Max plans include hands-on help customizing your membership site and implementing new features. Upgrade to PMPro Max now »
Last updated on November 19, 2026