Skip to content

Instantly share code, notes, and snippets.

View lubyagin's full-sized avatar

Александр lubyagin

View GitHub Profile
@andrewlimaza
andrewlimaza / make_lower_product_not_purchasable.php
Created February 12, 2018 09:04
Stop users from purchasing a lower membership level Paid Memberships Pro WooCommerce
<?php
/**
* This stops users from purchasing a lower level membership through WooCommerce. (Assume lower level ID is '1')
* If user has level 2 or 3, stop them from purchasing level 1 membership.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
// Stop users from purchasing a lower membership level via WooCommerce.
function pmpro_lower_level_is_purchasable( $is_purchasable, $product ) {
@andrewlimaza
andrewlimaza / change_pricing_based_on_level.php
Created February 12, 2018 07:46
Change Pricing Based On Level Paid Memberships Pro
<?php
/**
* Change the pricing of a membership level based on the level of user.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_charge_discount_for_level( $level ) {
// If the user does not have a level, bail.
if( ! pmpro_hasMembershipLevel() ){
@andrewlimaza
andrewlimaza / pmpro_age_check.php
Last active February 19, 2019 23:25
Users need to be 18 or older to register for Paid Memberships Pro Checkout
<?php
/**
* This will only allow users that are 18 years or older to signup on checkout.
* This requires a custom 'date' field using Register Helper.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function custom_pmpro_validate_user_age( $okay ) {
if( ! $okay ) {
@andrewlimaza
andrewlimaza / show_who_last_viewed.php
Last active November 18, 2022 23:41
Show 'Who Last Viewed' For WordPress Posts
<?php
// Add this code below to your active theme's functions.php or custom plugin.
/**
* Capture time when a user viewed a post only.
* Do not capture admin views, only users.
* Stores an array as $array['username'] => timestamp.
*/
function wll_save_when_viewed() {
@andrewlimaza
andrewlimaza / pmpro_add_link_to_account_page.php
Created January 26, 2018 12:47
Add Link to BBPress on Account Page of Paid Memberships Pro
@andrewlimaza
andrewlimaza / show_member_number_on_card.php
Last active August 28, 2023 07:18
Show member number on Membership Card Add On Paid Memberships Pro
<?php
/**
* This will show a member number on the membership card for Paid Memberships Pro. Please read all comments below!
* This requires the following - https://www.paidmembershipspro.com/generate-a-unique-member-number-for-display-on-membership-account-confirmation-email-and-more/
* At the time of this writing, created a custom page template and added in hook "do_action( 'pmpro_membership_card_additional_fields', $pmpro_membership_card_user );" to the relevant area.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* www.paidmembershipspro.com for help.
*/
@andrewlimaza
andrewlimaza / pmpro_show_time_on_invoice.php
Created January 22, 2018 07:05
Show checkout time for Paid Memberships Pro invoices.
<?php
/**
* Show the time of checkout on Paid Memberships Pro Invoices.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* See date parameters available to adjust time/date - http://php.net/manual/en/function.date.php#refsect1-function.date-parameters
* www.paidmembershipspro.com
*/
function pmpro_time_for_invoice( $invoice ) {
echo '<li><strong>Time of Checkout: </strong>' . date_i18n( "H:i", $invoice->timestamp ) . '</li>';
@andrewlimaza
andrewlimaza / send_validation_email.php
Created January 15, 2018 09:59
Send validation email when assigning membership level via code Paid Memberships Pro
<?php
/**
* Send validation email when assigning a membership level to a user using PHP code.
* Extended from example - https://www.paidmembershipspro.com/give-users-a-default-membership-level-at-registration/
* Adjust code accordingly to your needs, add to PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
add_filter("pmpro_login_redirect", "__return_false");
function my_pmpro_default_registration_level( $user_id ) {
@andrewlimaza
andrewlimaza / hide_recaptcha.php
Created January 11, 2018 10:22
Hide Recaptcha for Paid Memberships Pro Checkout for certain levels.
<?php
/**
* Remove the Captcha field for particular membership level.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function remove_pmpro_recaptcha() {
// Assume user is checking out for level 5. Change according to level you would like to hide the Recaptcha field.
@andrewlimaza
andrewlimaza / close_comments_for_non_members.php
Created January 10, 2018 10:15
Close comments for non-members Paid Memberships Pro
<?php
/**
* Close comments for non-members. Non-members will still be able to read the comments.
* Add this function to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_close_comments_non_members() {
if( !pmpro_hasMembershipLevel() ) {
$r = false;
}else{