Skip to content

Instantly share code, notes, and snippets.

View andrewlimaza's full-sized avatar

Andrew Lima andrewlimaza

View GitHub Profile
@andrewlimaza
andrewlimaza / pmpro_start_session.php
Created August 14, 2018 13:52 — forked from ideadude/pmpro_start_session.php
Tell PMPro to start the PHP session earlier.
/**
* Add this code into a custom plugin.
* You could also add a direct call to session_start() in your wp-config.php
* or another piece of code that runs early.
*/
add_action('plugins_loaded', 'pmpro_start_session');
@andrewlimaza
andrewlimaza / my_pmpro_after_change_membership_level.php
Last active February 21, 2022 14:14 — forked from strangerstudios/my_pmpro_after_change_membership_level.php
Only allow users to use the trial levels once with Paid Memberships Pro.
<?php
/**
* Only allow users to use the trial level once. This does not affect pre-existing members that had a level before this code is implemented.
* Be sure to change the $trial_levels variable in multiple places.
* You may add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
//record when users gain the trial level
function my_pmpro_after_change_membership_level($level_id, $user_id)
{
//set this to the id of your trial level
@andrewlimaza
andrewlimaza / generate_member_number.php
Created July 25, 2018 08:55 — forked from strangerstudios/generate_member_number.php
Generate a "Member Number" for WordPress users and show it on the PMPro account page.
<?php
/*
Member Numbers
* Change the generate_member_number function if your member number needs to be in a certain format.
* Member numbers are generated when users are registered or when the membership account page is accessed for the first time.
*/
//Generate member_number when a user is registered.
function generate_member_number($user_id)
{
@andrewlimaza
andrewlimaza / my_pmprowoo_get_membership_price.php
Created July 4, 2018 16:52 — forked from ideadude/my_pmprowoo_get_membership_price.php
Use the pmprowoo_get_membership_price filter to set prices for variable products with Paid Memberships Pro and WooCommerce
<?php
/**
* Use the pmprowoo_get_membership_price filter to set prices for variable products.
* Update the $membership_prices array.
* Each item in that array should have a key equal to the membership level id,
* and a value equal to an array of the form array( {variable_product_id} => {member_price} )
*
* Add this code into a custom plugin.
*/
function my_pmprowoo_get_membership_price( $discount_price, $level_id, $original_price, $product ) {
@andrewlimaza
andrewlimaza / pmpro-australia-gst.php
Last active July 23, 2018 10:21 — forked from strangerstudios/pmpro-australia-gst.php
Paid Memberships Pro - Australia GST
<?php
/*
Plugin Name: Paid Memberships Pro - Australia GST
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-australia-gst/
Description: Apply Australia GST to Checkouts with PMPro
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
<?php
/**
* Add the code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
//we have to put everything in a function called on init, so we are sure Register Helper is loaded
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
@andrewlimaza
andrewlimaza / hide_old_posts_from_members.php
Last active June 13, 2018 07:12 — forked from strangerstudios/hide_old_posts_from_members.php
Paid Memberships Pro: Hide Old Posts From New Members
/*
This code will create a content filter for all pages and posts to remove access to posts that were published before a member's join date. Only posts or pages which require membership will be hidden. Note that pages and posts that require membership will still be hidden from non-members regardless of the publish date.
The params passed are:
$hasaccess - (bool) what PMPro thinks about whether the user has access
$thepost - (post object) the post being checked, usually the current post
$theuser - (user object) the user being checked, usually the current user
$post_membership_levels - (array of levels) the levels this post requires (if any)
*/
add_filter("pmpro_has_membership_access_filter", "hide_old_posts_from_members", 10, 4);
@andrewlimaza
andrewlimaza / pmpro-select-membership-duration.php
Last active February 19, 2019 17:09 — forked from travislima/pmpro-select-membership-duration.php
Allows customers to select membership duration at checkout. Adjusts the amount charged and expiration date of the membership accordingly.
<?php
/*
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* Allows customers to select membership duration at checkout. Adjusts the amount charged and expiration date of the membership accordingly.
* Requires the Paid Memberships Pro Register Helper Add On to be installed and activated in order to work - https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
*/
function my_pmprorh_init() {
@andrewlimaza
andrewlimaza / pmpro-auto-password-generation.php
Created May 10, 2018 12:55 — forked from strangerstudios/pmpro-auto-password-generation.php
Auto generate passwords with Paid Memberships Pro
/*
Automatically generate password on checkout page.
Note: if you want to remove the entire user area and generate usernames and passwords, simply set the pmpro_skip_account_fields filter to return false.
Use the intstructions here (http://www.paidmembershipspro.com/documentation/advanced-techniques/templates/) to add a checkout page template with the password fields removed.
Uncheck the "Default WP notification email. (Recommended: Leave unchecked. Members will still get an email confirmation from PMPro after checkout.)" option in the PMPro Emails Settings tab.
*/
function my_generate_passwords()
@andrewlimaza
andrewlimaza / my_gettext_membership.php
Last active December 16, 2020 15:13 — forked from strangerstudios/my_gettext_membership.php
Change "Membership" to a different word with Paid Memberships Pro
// Change 'Membership' to 'Subscription' for Paid Memberships Pro.
function my_gettext_membership( $translated_text, $text, $domain ) {
if( "paid-memberships-pro" == $domain ) {
$translated_text = str_replace( "Membership Level", "Subscription", $translated_text );
$translated_text = str_replace( "membership level", "subscription", $translated_text );
$translated_text = str_replace( "membership", "subscription", $translated_text );
$translated_text = str_replace( "Membership", "Subscription", $translated_text );
}
return $translated_text;
}