Home / Archive / MemberPress: Require Specific Coupon to Register
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Require Specific Coupon to Register

The code will make a specific coupon mandatory for purchasing a specific membership. More than one coupon can be used with this code.

Code Preview
php
<?php
function mepr_only_with_coupon( $errors ) {
  $membership_id = 123; //Change this ID to your membership ID
  $coupons = array( 'IMRECOMMENDED', 'DISCOUNTED' ); //Change these titles to your coupon title(s)
  
  if( $_POST['mepr_product_id'] == $membership_id ) {
    if( !isset( $_POST['mepr_coupon_code'] ) || empty( $_POST['mepr_coupon_code'] ) || !in_array($_POST['mepr_coupon_code'], $coupons, false ) ) {
      $errors[] = "You must enter a valid coupon code to purchase this Membership";
    }
  }
  
  return $errors;
}
add_filter( 'mepr-validate-signup', 'mepr_only_with_coupon' );

Comments

Add a Comment