value generated for _membership_key meta

When a subscription is successful this meta value is populated with a seemingly random string, is there a way I can make it instead pull from a database or alternatively, if a 100% value coupon code is used, make the coupon value overwrite it?

Any help much appreciated,

Kind Regards

Jim

  • Vinod Dalvi

    Hi Jim,

    Welcome to the WPMU Dev community and thank you for your question.

    This _membership_key is generated by getting md5 value of user password and time using the following code.

    $key = md5($user->ID . $user->user_pass . time());

    This key is used to give you access the the members RSS feed, keep it safe and secret.

    Could you please tell me why you want to change its value so that i can help you to achieve it?

    is there a way I can make it instead pull from a database or alternatively, if a 100% value coupon code is used, make the coupon value overwrite it?

    Do you mean by "is there a way I can make it instead pull from a database" you want to fetch its value from database?

    Kind Regards,
    Vinod Dalvi

  • James

    Hi Vinod,

    Thanks for the quick reply. The site is for a discount card where customers are able to register for a website and purchase the card online where the _membership_key value becomes their unique membership ID, this number is then printed on a card with the expiry date and sent out the customer.

    However it is also be necessary for customers to be able to purchase the card offline (from highstreet shops) and simply register their card online. These cards will have pre printed numbers on them, which will be their unique membership ID's. I would like to use the coupon feature to apply a 100% discount to the value of the subscription so customers must simply enter the number on the card to earn the subscription.

    As is this will then generate a _membership_key for the offline purchasers which will not match the number on the front of their card. I simply need a way to add the string value entered as the coupon code form as additional meta data.

    Ideally this coupon code value would overwrite the _membership_key but I feel this is not possible.

    So my basic attempt so far:

    I have tried making my own custom meta value (offline_subsc_id) and calling the update_user_meta function in coupon.form.php but cannot get it to work.

    //my code

    $user_id = get_current_user_id();
    update_user_meta($user_id, 'offline_subsc_id', $coupon);

    //i call it after here

    // Check if there are any coupons and if there are any valid for this subscription
    if ( $coupon != false ) {
    // Check the coupon is a valid one
    $sub_id = (int)$_REQUEST['subscription'];
    if ( is_numeric( $sub_id ) && method_exists( $coupon, 'valid_for_subscription' ) && $coupon->valid_for_subscription( $sub_id ) ) {

    Hope this makes sense, let me know if not. The database solution would be an alternative where the $key is not generated by combining passwords/time but instead just checks a table of values (there would be thousands) and picks the next unused and sets that as the membership number for the user.

    Kind Regards

    Jamie

  • James

    Unfortunately not for my client.

    As a fix I just need to be able to add meta value data of a custom field when a coupon code is entered. Is this possible in coupon.form.php?

    So if the coupon code is accepted, it simply takes the value of the coupon and populates a custom field with it as here.

    $user_id = get_current_user_id();
    update_user_meta($user_id, 'offline_subsc_id', $coupon);

    Kind Regards

    Jamie