Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
andrewlimaza / redirect-non-members-to-content-restricted.php
Last active June 9, 2020 13:37
Redirect non-members to 'Content Restricted' BuddyPress page for normal content.
<?php
/**
* Redirect non-members away from 'normal' content to BuddyPress content restricted page.
* Requires the BuddyPress Integration to be installed - https://www.paidmembershipspro.com/add-ons/buddypress-integration/
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_template_redirect_require_membership_access() {
if ( ! pmpro_has_membership_access() && ! bp_current_component() && ! is_archive() && ! is_home() && function_exists( 'pmpro_bp_redirect_to_access_required_page' ) ) {
pmpro_bp_redirect_to_access_required_page();
@andrewlimaza
andrewlimaza / auto-populate-cf7-pmpro-members.php
Created March 8, 2019 12:13
Auto-populate Contact Form 7 select field with active member names [Paid Memberships Pro]
<?php
/**
* Auto-populate user names for active members in a field drop-down.
* This will assume you are using a select field named "membership-list"
* The value of the select is the user's email and the label is set to the user's login name.
* Data Example: <option value="someemail@test.com">Test User</option>
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_auto_populate_members ( $tag, $unused ) {
@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' );
@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' );
}
@andrewlimaza
andrewlimaza / load-custom-css-level-pmpro.php
Created October 19, 2018 11:00
Load custom CSS for Membership Checkout for specific level - Paid Memberships Pro
<?php
/**
* Load custom CSS on checkoutpage for specific membership level in Paid Memberships Pro.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function load_css_for_level_checkout(){
global $pmpro_pages;
@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
@andrewlimaza
andrewlimaza / redirect-member-away-from-page.php
Created August 6, 2018 08:13
redirect user away from the page if they do not have a specific membership level.
<?php
/**
* This will redirect members with level 1 from site.com/page-slug to the home page.
* Please adjust accordingly and add to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function redirect_member_from_page_x() {
if ( is_page( 'page-slug' ) && pmpro_hasMembershipLevel( 1 ) ) {
wp_redirect( home_url() ); //redirect to home page. Change home_url() to home_url( '/page-slug' ) to redirect to specific page.
@andrewlimaza
andrewlimaza / show-renewal-link-on-30-days-or-less.php
Last active January 23, 2023 13:47
Change when to show the renewal link on Paid Memberships Pro account page.
@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/
*/
@andrewlimaza
andrewlimaza / set-membership-based-on-variation-product.php
Last active November 15, 2021 09:06
Assign membership level based on variation product purchase.
<?php
/**
* Assign a membership level based on product ID variation purchase.
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function add_membership_for_variation_pricing( $order_id ) {
global $wpdb, $pmprowoo_product_levels;
// quitely exit if PMPro isn't active