You can automatically apply a MemberPress coupon to all membership levels. This way, members don’t have to find, copy, and paste coupons themselves. To do this, you can add a code snippet that will fill in coupon codes for them.
This guide explains how to add the code snippet and adjust it to use your Coupons MemberPress.
Adding the Code Snippet
You can add the code snippet directly to your child-theme’s functions.php file. However, it’s recommended to add it via a code snippet plugin, such as WPCode.
Follow the steps below to install the WPCode plugin and add the code snippet:
- Naviguez jusqu'à la page Dashboard > Plugins > Add Plugin.
- Rechercher WPCode and locate the plugin.

- Cliquez sur le bouton Installer maintenant bouton.
- Cliquez sur le bouton Activer bouton.
- Se rendre à l'adresse suivante Dashboard > Code Snippets > Add Snippet > Add Your Custom Code (New Snippet).

- Cliquez sur le bouton + Add Custom Snippet bouton.
- Choisir Extrait PHP.

- Add a title for the snippet and paste the following code in the Code Preview section.
// Auto-Populate MemberPress Registration Coupon Codes
function mepr_auto_populate_coupon() {
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Wait for MemberPress scripts to initialize
setTimeout(function() {
var c = document.querySelector('.mepr_coupon input.mepr-coupon-code');
if (c) {
// Paste coupon below to replace 'YOURCOUPON'
c.value = 'YOURCOUPON';
// Trigger all relevant events for MemberPress
['input', 'keyup', 'change', 'blur'].forEach(function(evtName) {
var evt = new Event(evtName, { bubbles: true });
c.dispatchEvent(evt);
});
}
}, 300);
});
</script>
<?php
}
add_action( 'wp_head', 'mepr_auto_populate_coupon' );

- Cliquez sur le bouton Save Snippet bouton.
Adjusting and Activating the Code Snippet
Follow these steps to adjust and activate the code snippet to auto-load the coupon code.
- Naviguez jusqu'à Dashboard > MemberPress > Coupons.

- Copy the coupon code from the Code column. If you do not have a coupon, create a new one.
- Naviguez jusqu'à Dashboard > Code Snippets.
- Click on the code snippet that was added in the previous section.
- Remplacer YOURCOUPON in the code snippet with the code you wish to use on the following line of code. Here is an example of how to replace “YOURCOUPON” with “DISCOUNT10.”
// Paste coupon below to replace 'YOURCOUPON'
c.value = 'DISCOUNT10';

- Activate the snippet.

- Cliquez sur le bouton Mise à jour bouton.
Testing the Coupon Codes During Registration
The coupon code added in the code snippet should automatically populate on registration forms. To test it, follow the steps below.
- Open any membership from Tableau de bord > MemberPress > Adhésions in an Incognito (private) Window in your browser.
- Review the invoice amount and total amount to ensure the coupon is applied automatically.

Applying Coupon Codes Automatically on Registration
The code snippet automatically applies a single coupon code to all membership levels on the site. This makes signing up easier by eliminating the need for users to manually enter the code.
By default, the coupon field is hidden in MemberPress registration forms. Users see a “Have a discount code” link; clicking it displays an input field for the coupon code. You can add a code snippet to auto-expand the coupon field on all MemberPress registration forms. This ensures users see the field without clicking a link.
For specific campaigns or membership tiers, site administrators can apply different coupons using a URL parameter. This means users can have different coupons automatically applied based on the link they click to register.
En outre, WPCode allows conditional logic to control when and for whom the coupon code is applied. You can set conditions to ensure the coupon applies only to logged-in users or to those with a specific membership.