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 Cupons 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 Código WPC.
Follow the steps below to install the WPCode plugin and add the code snippet:
- Navegue até a seção Dashboard > Plugins > Add Plugin.
- Procurar por Código WPC and locate the plugin.

- Clique no botão Instalar agora botão.
- Clique no botão Ativar botão.
- Vá para Dashboard > Code Snippets > Add Snippet > Add Your Custom Code (New Snippet).

- Clique no botão + Add Custom Snippet botão.
- Escolha Snippet de PHP.

- Add a title for the snippet and paste the following code in the Code Preview seção.
// 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' );

- Clique no botão Save Snippet botão.
Adjusting and Activating the Code Snippet
Follow these steps to adjust and activate the code snippet to auto-load the coupon code.
- Navegue até Dashboard > MemberPress > Coupons.

- Copy the coupon code from the Code column. If you do not have a coupon, create a new one.
- Navegue até Dashboard > Code Snippets.
- Click on the code snippet that was added in the previous section.
- Substituir 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.

- Clique no botão Atualização botão.
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 Painel de controle > MemberPress > Associações 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.
Além disso, 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.