Zusätzliches Menü

Holen Sie sich MemberPress noch heute! Lassen Sie sich für die Inhalte, die Sie erstellen, bezahlen! MemberPress jetzt kaufen

Auto-Populate Coupon Codes on Registration Forms

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 MemberPress Gutscheine.

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:

  1. Navigieren Sie zum Dashboard > Plugins > Add Plugin.
  2. Suche nach WPCode and locate the plugin.
  1. Klicken Sie auf die Jetzt installieren Taste.
  2. Klicken Sie auf die Aktivieren Sie Taste.
  3. Kopf nach Dashboard > Code Snippets > Add Snippet > Add Your Custom Code (New Snippet).
  1. Klicken Sie auf die + Add Custom Snippet Taste.
  2. Wählen Sie PHP-Schnipsel.
  1. Add a title for the snippet and paste the following code in the Code Preview Abschnitt.
// 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' );
  1. Klicken Sie auf die Save Snippet Taste.

Adjusting and Activating the Code Snippet

Follow these steps to adjust and activate the code snippet to auto-load the coupon code.

  1. Navigieren Sie zu Dashboard > MemberPress > Coupons.
  1. Copy the coupon code from the Code column. If you do not have a coupon, create a new one.
  2. Navigieren Sie zu Dashboard > Code Snippets.
  3. Click on the code snippet that was added in the previous section.
  4. Ersetzen Sie 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';
  1. Activate the snippet.
  1. Klicken Sie auf die Update Taste.

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.

  1. Open any membership from Dashboard > MemberPress > Mitgliedschaften in an Incognito (private) Window in your browser.
  2. 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.

Zusätzlich, 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.

War dieser Artikel hilfreich?

Verwandte Artikel

Computerfrau

Holen Sie sich MemberPress noch heute!

Lassen Sie sich für die von Ihnen erstellten Inhalte bezahlen.