Skip to content

Instantly share code, notes, and snippets.

@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 ) {
@ideadude
ideadude / autocomplete_virtual_orders.php
Created August 17, 2018 13:58
Autocomplete WooCommerce orders with only virtual products.
/**
* Autocomplete orders with only virtual products.
* From the 2nd edition of Building Web Apps with WordPress
* https://bwawwp.org
*/
function autocomplete_virtual_orders($order_id) {
//get the existing order
$order = new WC_Order($order_id);
//assume we will autocomplete
@strangerstudios
strangerstudios / $pmpro_non_renewal_levels.php
Created March 28, 2016 16:22
Don't allow early renewals for certain levels with Paid Memberships Pro.
/*
Don't allow early renewals for certain levels.
Change the level IDs in the $pmpro_non_renewal_levels global array, then
add this code to your active theme's functions.php or a custom plugins.
*/
//define levels in global
global $pmpro_non_renewal_levels;
$pmpro_non_renewal_levels = array(1,2,3); //change this to the level IDs of the levels you don't want users to renew for
@andrewlimaza
andrewlimaza / hide-sidebar-from-member.php
Created December 11, 2018 09:12
Remove custom sidebar based on membership level.
<?php
/**
* Remove custom sidebar based on user's membership level.
* Add this code to your PMPro Customizations Plugin -
*/
function my_pmpro_hide_sidebar_from_members(){
if ( ! pmpro_hasMembershipLevel( 1 ) ) {
unregister_sidebar( 'my-sidebar-id' );
}
@strangerstudios
strangerstudios / my_pmpro_disable_member_emails.php
Created March 10, 2017 19:34
Disable member emails for specific levels.
function my_pmpro_disable_member_emails($recipient, $email)
{
$user = get_user_by('login', $email->data['user_login']);
$level = pmpro_getMembershipLevelForUser($user->ID);
$disabled_levels = array(1,2,3); //update this to include ids of all levels you want to disable emails for
if(!empty($level) && !empty($level->id) && in_array($level->id, $disabled_levels))
$recipient = NULL;
@andrewlimaza
andrewlimaza / restrict_woo_product_non_members.php
Last active July 2, 2019 22:32
Restrict particular product for WooCommerce and Paid Memberships Pro
<?php
/**
* This function allows you to restrict a single WooCommerce product to non-members (disables add to cart button)
* Price will still be displayed.
* Add the following code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function hide_add_to_cart_for_non_members( ){
@andrewlimaza
andrewlimaza / dont-apply-level-for-members-woo.php
Last active July 2, 2019 22:33
Stop users from changing membership level on checkout on WooCommerce
<?php
/**
* Stop existing members from changing levels when purchasing a product on WooCommerce.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function woo_dont_apply_level_for_existing_members() {
if ( pmpro_hasMembershipLevel( '1' ) ) {
remove_action( 'woocommerce_order_status_completed', 'pmprowoo_add_membership_from_order' );
@strangerstudios
strangerstudios / my_pmpro_registration_checks.php
Created January 25, 2014 18:17
Don't let existing members downgrade example.
/*
Don't let exisisting members checkout for free level.
*/
function my_pmpro_registration_checks($okay)
{
//only check if things are okay so far
if($okay)
{
global $pmpro_level;
@ideadude
ideadude / my_pmprorh_init_buddypress_fields.php
Created June 29, 2018 14:07
Example of defining PMPro Register Helper Fields Synchronized to BuddyPress XProfile Fields
/**
* Based on the Register Helper example.
* We've added a "buddypress" option for each field
* set to the XProfile name we used when setting up
* the fields in the BuddyPress extended profile.
* If the PMPro BuddyPress Add On is activated
* then the fields will be synchronized.
* Register Helper: https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
* PMPro BuddyPress: https://www.paidmembershipspro.com/add-ons/buddypress-integration/
*/
@pbrocks
pbrocks / pmpro-cancel-on-next-payments-date.php
Last active July 17, 2019 14:26 — forked from strangerstudios/pmpro_cancel_on_next_payments_date.php
Change PMPro membership cancellation to set expiration date for next payment instead of cancelling immediately.
<?php
/**
* 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.
*/
/**