Skip to content

Instantly share code, notes, and snippets.

@cartpauj
cartpauj / mepr-autoembed-thankyou-page-messages.php
Created June 7, 2016 16:09
WP Autoembed MemberPress thank you page messages
<?php
/* Enter Your Custom Functions Here */
function mepr_autoembed_thankyou_message($message) {
global $wp_embed;
if(!class_exists('MeprTransaction')) { return $message; }
if(!isset($_REQUEST['trans_num'])) { return $message; }
$txn = new MeprTransaction();
@cartpauj
cartpauj / add-merge-fields.php
Created June 7, 2016 20:15
Add custom MERGE fields using MemberPress and their MailChimp 3.0 integration
<?php
//hooks in to MemberPress $args array before sending new subscriber info to MailChimp
function mepr_add_my_tags($args, $member) {
$zip = get_user_meta($member->ID, 'mepr-address-zip', true);
$country = get_user_meta($member->ID, 'mepr-address-country', true);
if($zip) {
$args['merge_fields']['MMERGE6'] = $zip; //YOU'LL NEED TO CHANGE MMERGEX TO MAP THEM TO YOUR OWN TAG VALUES
}
@cartpauj
cartpauj / pretty-link-pro-permalinks.php
Created June 10, 2016 17:56
Pretty Link Pro - Replace WordPress' Permalinks with pretty links when possible
@cartpauj
cartpauj / mepr-magazine-model.php
Last active May 19, 2021 14:03
Content added after the user signed up is unprotected. Magazine style almost.
<?php
function mepr_override_protection($protect, $post) {
$user = MeprUtils::get_currentuserinfo();
if($user === false) { return $protect; }
//Set the registration date back one month, to ensure they have access to current issue.
$registration_date = strtotime(MeprUser::get_user_registration_date($user->ID)) - MeprUtils::months(1);
$post_date = strtotime($post->post_date);
$active_product_subscriptions = $user->active_product_subscriptions();
@cartpauj
cartpauj / mepr-ecommerce.php
Last active January 17, 2024 22:11
Google eCommerce Tracking for MemberPress Thank You Pages
<?php
//PASTE THIS CODE IN A PLUGIN LIKE My Custom Functions (RECOMMENDED) OR IN YOUR THEME'S functions.php FILE
//THIS ASSUMES YOU HAVE THE GOOGLE ANALYTICS JAVASCRIPT INCLUDED ALREADY
function echo_ga_tracking_script() {
if(isset($_GET['membership']) && isset($_GET['trans_num'])) {
$txn = MeprTransaction::get_one_by_trans_num($_GET['trans_num']);
if(isset($txn->id) && $txn->id > 0) {
//Echo the script to the HTML <head>
?>
@cartpauj
cartpauj / mepr-hijack-cancel-url.php
Last active April 22, 2022 19:39
Hijack MemberPress cancel URL and show our own custom message/upsell whatever before the user cancels
<?php
function cspf_custom_cancel_link($html, $sub) {
ob_start();
?>
<a href="?action=upsell&sub=<?php echo $sub->id; ?>">Cancel</a>
<?php
return ob_get_clean();
}
add_action('mepr_custom_cancel_link', 'cspf_custom_cancel_link', 10, 2);
@cartpauj
cartpauj / mepr-membership-to-auto-aff.php
Created July 12, 2016 17:36
Make Members affiliates in Affiliate Royale only if they register for certain MemberPress membership levels
<?php
/*
* This only works if the Affiliate Royale plugin
* is set to NOT create affiliates from new users automatically
*/
function make_new_user_affiliate($txn) {
//CHANGE THIS ARRAY TO THE IDS OF THE MEMBERSHIPS YOU WANT TO AUTO CREATE AFFS WITH
$membership_ids_for_affs = array(123,321,789);
if(in_array($txn->product_id, $membership_ids_for_affs, false) && class_exists('WafpUser')) {
@cartpauj
cartpauj / tracking_pixel_memberpress_footer.php
Last active February 20, 2019 20:50
Adds a tracking pixel with sale info in the wp_footer on MemberPress Thank You page
@cartpauj
cartpauj / mepr-email-validate-field.php
Last active June 3, 2021 04:50
Add Email Validation Field to MemberPress checkout form
<?php
//The following code could be pasted into a plugin like My Custom Functions
function display_validate_email_field() {
?>
<div class="mp-form-row mepr_validate_email">
<div class="mp-form-label">
<label><?php _ex('Verify Email:*', 'ui', 'memberpress'); ?></label>
<span class="cc-error"><?php _ex('Invalid Email', 'ui', 'memberpress'); ?></span>
</div>
<input type="email" name="user_validate_email" id="user_validate_email" class="mepr-form-input" value="" required />
@cartpauj
cartpauj / mepr-dynamic-trial-periods.php
Last active April 23, 2021 12:59
Dynamic trial periods on a membership in MemberPress
<?php
//Sets up a trial period on MemberPress such that ALL users renew on March 31st.
function mepr_days_until($date){
return (isset($date)) ? floor((strtotime($date) - time())/60/60/24) : false;
}
function mepr_update_mepr_trial_period() {
$prd = new MeprProduct(123); //CHANGE 123 to the ID of your Membership level
$last_check = get_option('mepr_trial_period_last_checked-'.$prd->ID, 0);