0

I’m quite new to WordPress – and coding in general except I did a lot of SQL, R Matlab etc during my studies a long time ago so I can learn if I know where to search :-). But php, javascript etc are pretty new to me.

I have an “assignment” I don’t know where to start with:

I want to use Mailster to send emails because it can display custom tags to users (documentation here: https://kb.mailster.co/add-custom-dynamic-tags-to-your-newsletter/)

I would want to send users their own referral link / code at the bottom of my first campaign. The referral code is generated by WPGens https://wpgens.helpscoutdocs.com/.

Here is an example that they give to generate a promo code –

function get_subscribers_coupon( $subscriber_id ) {
$seed = AUTH_SALT;
$length = 10;
$code = substr( strtoupper( base_convert( md5( $seed . $subscriber_id 
), 16, 36 ) ), 0, $length );
return $code;
}

mailster_add_tag( 'coupon', function( $option, $fallback, $campaignID = 
null, $subscriberID = null ) {

// make sure the subscriber ID is set
if ( ! is_null( $subscriberID ) ) {
    return get_subscribers_coupon( $subscriberID );
}

// return the fallback "NOCOUPONCODE4U"
return $fallback;
} );

Regarding my specific problem, from what I can see the referral code I need to return is stored in my wp_usermeta table with one line per user id, meta_key = “gens_referral_id” and meta_value = the_referral_code that I want to show in the newsletter – https://monosnap.com/file/j3zuxY65c4EBs8tG6rWv23X1Fhq90B

Do I need to query the table from a php function? Or do theses user meta tags live somewhere else? Could you help me writing the function to return this as a custom dynamic tag?

More generally I wonder how you guys test the php code that you write, how you know the variables you can pull from etc?

Thanks so much!! Reynald

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.