Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
strangerstudios / pmpro_after_change_membership_level_default_level.php
Last active April 7, 2022 20:32
Place a PMPro member in another level when they cancel... unless they are cancelling from that level.
/*
When users cancel (are changed to membership level 0) we give them another "cancelled" level.
Can be used to downgrade someone to a free level when they cancel.
Will allow members to the "cancel level" to cancel from that though.
*/
function my_pmpro_after_change_membership_level_default_level($level_id, $user_id)
{
//set this to the id of the level you want to give members when they cancel
$cancel_level_id = 1;
@strangerstudios
strangerstudios / my_pmpro_has_membership_access_filter.php
Created January 25, 2014 18:49
Filter pmpro_has_membership_access so paid members have access to all addon packages, but free members must pay the per post price. Edit the $my_paid_level_ids array to include an array of your paid level ids. Put this code in your active theme's functions.php or a custom WordPress plugin.
<?php
/*
Filter pmpro_has_membership_access based on paid membership access.
*/
function my_pmpro_has_membership_access_filter( $hasaccess, $mypost, $myuser, $post_membership_levels ) {
$my_paid_level_ids = array(5,6,7);
// Check if the user doesn't have access
if( ! $hasaccess ) {
// If this post has membership levels associated with it and is supposed to be locked by the Addon Plugin
@andrewlimaza
andrewlimaza / set-membership-based-on-variation-product.php
Last active November 15, 2021 09:06
Assign membership level based on variation product purchase.
<?php
/**
* Assign a membership level based on product ID variation purchase.
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function add_membership_for_variation_pricing( $order_id ) {
global $wpdb, $pmprowoo_product_levels;
// quitely exit if PMPro isn't active
@strangerstudios
strangerstudios / pmpro_cancel_on_next_payments_date.php
Last active May 20, 2021 11:17
Change PMPro membership cancellation to set expiration date for next payment instead of cancelling immediately.
/*
Change cancellation to set expiration date for next payment instead of cancelling immediately.
Assumes orders are generated for each payment (i.e. your webhooks/etc are setup correctly).
Since 2015-09-21 and PMPro v1.8.5.6 contains code to look up next payment dates via Stripe and PayPal Express APIs.
*/
//before cancelling, save the next_payment_timestamp to a global for later use. (Requires PMPro 1.8.5.6 or higher.)
function my_pmpro_before_change_membership_level($level_id, $user_id) {
//are we on the cancel page?
@strangerstudios
strangerstudios / pmpro_cancelled_level.php
Last active May 12, 2021 22:05
Place a PMPro member in another level when they cancel.
/*
When users cancel (are changed to membership level 0) we give them another "cancelled" level. Can be used to downgrade someone to a free level when they cancel.
*/
function pmpro_after_change_membership_level_default_level($level_id, $user_id)
{
//if we see this global set, then another gist is planning to give the user their level back
global $pmpro_next_payment_timestamp;
if(!empty($pmpro_next_payment_timestamp))
return;
@strangerstudios
strangerstudios / gist:5573829
Last active April 16, 2021 23:43
Paid Memberships Pro customization to only let members of a certain level checkout if a discount code was used.
/*
Only let level 1 members sign up if they use a discount code.
Place this code in your active theme's functions.php or a custom plugin.
*/
function my_pmpro_registration_checks_require_code_to_register($pmpro_continue_registration)
{
//only bother if things are okay so far
if(!$pmpro_continue_registration)
return $pmpro_continue_registration;
@strangerstudios
strangerstudios / my_template_redirect_upgrade.php
Created April 14, 2015 16:12
Redirect away from the checkout page if you don't have a required level with Paid Memberships Pro.
/*
Redirect away from the checkout page if you don't have a required level.
*/
function my_template_redirect_upgrade()
{
global $pmpro_pages, $pmpro_level;
if(empty($pmpro_pages))
return;
@strangerstudios
strangerstudios / pmpro_hide_level_from_levels_page.php
Last active April 8, 2021 18:21 — forked from greathmaster/pmpro-restrict-visibility-of-levels-on-levels-page.php
Limits the visibility of a level on the Levels page. Unlike setting "Allow Signups" members can access the checkout page to renew if needed.
<?php
//Save the pmpro_show_level_ID field
function pmpro_hide_level_from_levels_page_save( $level_id ) {
if( $level_id <= 0 ) {
return;
}
$limit = $_REQUEST['pmpro_show_level'];
update_option( 'pmpro_show_level_'.$level_id, $limit );
}
add_action( 'pmpro_save_membership_level','pmpro_hide_level_from_levels_page_save' );
@strangerstudios
strangerstudios / gist:3100680
Created July 12, 2012 20:18
Hidden Levels for Paid Memberships Pro
<?php
/*
Plugin Name: PMPro Hidden Levels
Plugin URI: http://www.paidmembershipspro.com/pmpro-hidden-levels/
Description: With this plugin, select levels are removed from the levels page but still available for checkout if you visit the checkout URL directly.
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
@andrewlimaza
andrewlimaza / remove_billing_example.php
Created June 12, 2017 07:48
Remove 'Billing' from 'Billing Address' title in Paid Memberships Pro.
<?php
/**
* Copy the function below into your PMPro Customizations plugin - http://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* This function uses the gettext filter which will change all text occurences of Billing Address to Address in Paid Memberships Pro.
*/
function change_text_billing_pmpro( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Billing Address' :
$translated_text = __( 'Address', 'paid-memberships-pro' );
break;