Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / my_approve_user_if_already_approved.php
Created Feb 18, 2022
PMPro Approvals: If a user was approved for any other level, consider them approved for every level.
View my_approve_user_if_already_approved.php
<?php
/**
* If a user was approved for any other level, consider them approved for every level.
* Requires the PMPro Approval Process for Membership Add On - https://www.paidmembershipspro.com/add-ons/approval-process-membership/
* Must be using PMPro Approvals version 1.4.2 or higher.
* Add this code to your site following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_approve_user_if_already_approved( $approved, $user_id, $level_id, $user_approval ) {
@ideadude
ideadude / pmpro_membership_content_filter_debug.php
Created Feb 9, 2022
Debug PMPro's pmpro_membership_content_filter() function.
View pmpro_membership_content_filter_debug.php
<?php
/**
* We can use the pmpro_membership_content_filter filter in
* the pmpro_membership_content_filter() function to debug
* and see what the $content and $hasaccess vars are set to
* at the time of running.
*
* IMPORTANT: This code will effectively break your site with
* the debug info. Only use this for a moment, then deactivate it.
*
@ideadude
ideadude / my_pmpro_cancel_levels_one_by_one
Last active Feb 8, 2022
When cancelling "all levels" in PMPro, do them one at a time so CONPD works.
View my_pmpro_cancel_levels_one_by_one
<?php
/**
* This gist updates the "cancel all memberships" link on the cancel page
* to pass the level ids into the page instead of "all".
* This will ensure that all the levels are cancelled one by one.
* In addition to sending a separate email for each cancellation,
* this also ensures the $old_level parameter is sent to the
* pmpro_cancelMembershipLevel() function so Add Ons like the
* Cancel on Next Payment Date one continue to work.
*
@ideadude
ideadude / my_keep_members_only_products_out_of_carts.php
Created Jan 6, 2022
Prevent non-members from adding member products to their cart with WooCommerce and PMPro.
View my_keep_members_only_products_out_of_carts.php
<?php
/**
* Prevent non-members from adding member products to their cart.
* This requires the PMPro CPT Add On be installed and
* each product should be checked for which levels are required.
*/
function my_keep_members_only_products_out_of_carts( $is_purchasable, $product ) {
// Not purchasable for some other reason.
if( ! $is_purchasable ) {
return $is_purchasable;
@ideadude
ideadude / my_hide_members_only_products_from_archives.php
Created Jan 6, 2022
Also hide members-only "products" CPT from archives.
View my_hide_members_only_products_from_archives.php
<?php
/**
* Also hide members-only "products" CPT from archives.
* You must use the PMPro CPT Add On and then check a produc to require membership.
* And also set the "Filter searches and archives?" option to Yes in the PMPro advanced settings.
*/
function my_hide_members_only_products_from_archives( $post_types ) {
if ( ! in_array( 'product', $post_types ) ) {
$post_types[] = 'product';
}
@ideadude
ideadude / my_pmproz_added_order_data_add_phone.php
Created Jan 2, 2022
Add phone number to the data array sent to Zapier when a new PMPro order is made.
View my_pmproz_added_order_data_add_phone.php
<?php
/**
* Add phone number to the data array sent to Zapier
* when a new PMPro order is made.
*
* This gist requires the pmpro-zapier plugin.
* For information on how to add code snippets: https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
function my_pmproz_added_order_data_add_phone( $data, $order, $user_id ) {
$data['phonenumber'] = get_user_meta( $user_id, 'pmpro_bphone', true );
@ideadude
ideadude / hide_fee.css
Created Dec 24, 2021
CSS to hide the fee on the account page in Paid Memberships Pro.
View hide_fee.css
/* Remove the level fee column */
#pmpro_account-membership table.pmpro_table .pmpro_account-membership-levelfee {
display: none;
}
#pmpro_account-membership table.pmpro_table tr th:nth-child(1) {
display: none;
}
@ideadude
ideadude / my_hide_expiration_text_on_levels_page.php
Created Dec 19, 2021
Hide the expiration text on the levels page with PMPro.
View my_hide_expiration_text_on_levels_page.php
<?php
/**
* Hide the expiration text on the levels page with PMPro.
* Add this code into a custom plugin or code snippet.
*/
function my_hide_expiration_text_on_levels_page( $text ) {
global $pmpro_pages;
if ( ! empty( $pmpro_pages['levels'] && is_page( $pmpro_pages['levels'] ) ) ) {
$text = '';
}
@ideadude
ideadude / my_add_extra_expiration_warning_templates.php
Last active Dec 13, 2021
Send extra expiration warning emails with individual templates when using PMPro and the Extra Expiration Warning Emails add on.
View my_add_extra_expiration_warning_templates.php
<?php
/**
* Send extra expiration warning emails with individual templates.
* Make sure the Extra Expiration Warning Emails Add On is also active.
* https://www.paidmembershipspro.com/add-ons/extra-expiration-warning-emails-add-on/
*
* Then add this code into a custom plugin or code snippet.
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
// Tell the expiration warnings add on to use our templates.
@ideadude
ideadude / automatically-approve-previously-approved.php
Created Dec 3, 2021 — forked from travislima/automatically-approve-previously-approved.php
Automatically approve, previously approved members. [Paid Memberships Pro]
View automatically-approve-previously-approved.php
<?php
/**
* Automatically approve any previously approved member.
* Requires the PMPro Approval Process for Membership Add On - https://www.paidmembershipspro.com/add-ons/approval-process-membership/
* Add this code to your site following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_automatically_approve_previously_approved( $level_id, $user_id, $cancelled_level ) {
if ( ! class_exists( 'PMPro_Approvals' ) ) {