Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
strangerstudios / pmpro_international_address_hooks.php
Last active December 28, 2021 04:38
Using Paid Memberships Pro hooks to enable international addresses
<?php
/*
Add this code to your theme's functions.php file to update the checkout page to support international credit cards.
*/
/*
First we need to enable international addresses. We just use the pmpro_international_addresses hook and return true.
This will add a "countries" dropdown to the checkout page.
*/
function my_pmpro_international_addresses()
{
@strangerstudios
strangerstudios / pmpro-redirect-non-members.php
Created November 2, 2011 02:58
Paid Memberships Pro Redirect Non-members to Login/Homepage
/*
Redirect to login or homepage if user is logged out or not a member
Add this code to your active theme's functions.php file.
*/
function my_template_redirect()
{
global $current_user;
$okay_pages = array(pmpro_getOption('billing_page_id'), pmpro_getOption('account_page_id'), pmpro_getOption('levels_page_id'), pmpro_getOption('checkout_page_id'), pmpro_getOption('confirmation_page_id'));
@strangerstudios
strangerstudios / gist:1389944
Created November 23, 2011 21:17
Paid Memberships Pro Extra Checkout/Profile Fields Example
<?php
/*
Adding First and Last Name to Checkout Form
*/
//add the fields to the form
function my_pmpro_checkout_after_password()
{
if(!empty($_REQUEST['firstname']))
$firstname = $_REQUEST['firstname'];
@strangerstudios
strangerstudios / gist:1421978
Created December 2, 2011 05:56
Paid Memberships Pro Different Payment Options at Checkout for One Level
/*
PMPro Example Offering Monthly and Annual Options on Checkout Page
This code assumes your levels have an annual recurring cost.
The first function converts your annual prices into monthly prices.
*/
function my_getMonthlyPriceFromAnnualPrice($price)
{
//divide by 10 and round down to nearest dollar
return floor($price / 10);
}
@strangerstudios
strangerstudios / gist:1453435
Created December 9, 2011 21:45
PMPro Disable Membership Dropdown on Profile Page For Users with Gateway Subscriptions
/*
Disable the membership level dropdown in the admin if the user has a subscription at the gateway.
This will keep admins from accidentally cancelling subscriptions.
Note: Requires PMPro version 1.3.7+
*/
function my_pmpro_profile_show_membership_level($show, $user)
{
global $wpdb;
//if the user's membership level is attached to a gateway, disable this field
$last_invoice = new MemberOrder();
@strangerstudios
strangerstudios / gist:1602202
Created January 12, 2012 18:22
Paid Memberships Pro and WP e-Commerce Integration Example
/*
Paid Memberships Pro/WP e-Commerce Integration
Description:
This group of functions will add a secure sign up link to the confirmation message for a specific product setup with WP E-commerce.
The session id from the order is passed to the PMPro checkout form, and will allow registration for a membership level that is otherwise disabled.
Once the user registers, the session id is added to the usermeta table as pmpro_sessionid_used so the session id can only be used once.
Requirements:
The Paid Memberships Pro plugin (v1.3.8 or higher) must be enabled.
@strangerstudios
strangerstudios / gist:1633637
Last active September 29, 2015 16:57
Locking Down bbPress Forums using Paid Memberships Pro
/*
*****
UPDATE: This gist is no longer needed.
The better way to integrate PMPro and bbPress is to the use the pmpro-bbpress plugin,
which is now available in the WordPress repository:
http://wordpress.org/plugins/pmpro-bbpress/
*****
@strangerstudios
strangerstudios / gist:1663916
Created January 23, 2012 15:50
Restrict Access to WordPress Pages Within a Time Frame Using Paid Memberships Pro
/*
Functions to give access to certain pages within a timeframe.
Set the $pages and $levels arrays.
*/
function my_pmpro_has_membership_access_filter($hasaccess, $mypost, $myuser, $post_membership_levels)
{
$pages = array(214); // page ids
$levels[1] = array("2012-01-01", "2012-04-01"); // $level[level_id] = array(start_date, end_date);
$levels[2] = array("2012-02-01", "2012-05-01"); // date format is YYYY-MM-DD
@strangerstudios
strangerstudios / gist:1894897
Created February 23, 2012 20:29
Adding Shipping Address to Paid Memberships Pro
<?php
/*
Plugin Name: PMPro Shipping
Plugin URI: https://gist.github.com/gists/1894897/
Description: Add shipping to the checkout page and other updates.
Version: .2.1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
Note that this plugin requires PMPro 1.3.19 or higher to function fully.
@strangerstudios
strangerstudios / gist:1974258
Created March 4, 2012 18:20
Samples Checkout Template for Paid Memberships Pro
<?php
/*
Template Name: Buy
*/
/*
To make a checkout template for your site and PMPro.
1. Create a template page based on your page.php, single,php, index.php, etc.
2. Find the area where the post_content usually goes.