Skip to content

Instantly share code, notes, and snippets.

View ronalfy's full-sized avatar
🏠
Working from home

Ronald Huereca ronalfy

🏠
Working from home
View GitHub Profile
@ronalfy
ronalfy / pmpro-switch-themes-per-level.php
Created March 23, 2020 14:02
Paid Memberships Pro - Switch Theme Per Level
<?php
function pmpro_change_theme_per_level( $theme ) {
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) {
return $theme;
}
if ( pmpro_hasMembershipLevel( 1 ) ) {
return 'twentyeleven';
} elseif ( pmpro_hasMembershipLevel( 2 ) ) {
return 'twentyfourteen';
}
@ronalfy
ronalfy / pmpro-limit-discount-code-url-logged-in-status.php
Created March 24, 2020 19:00
Paid Memberships Pro - Limit Discount Code by URL and Logged In Status
<?php
function my_pmpro_show_discount_code( $show ) {
if ( empty( $_REQUEST['discount_code'] ) || is_user_logged_in() ) {
$show = false;
}
return $show;
}
add_filter( 'pmpro_show_discount_code', 'my_pmpro_show_discount_code' );
@ronalfy
ronalfy / pmpro-exclude-post-limit-addon.php
Created March 27, 2020 01:03
Paid Memberships Pro Exclude Post from Limit
<?php
function pmpro_levels_exclude_page() {
if ( is_single( 'hello-world' ) ) {
remove_action( 'wp', 'pmpro_lpv_wp' );
add_filter( 'pmpro_has_membership_access_filter', '__return_true' );
}
}
add_action( 'wp', 'pmpro_levels_exclude_page', 9 );
@ronalfy
ronalfy / pmpro-redirect-membership-account.php
Created March 30, 2020 17:46
Paid Memberships Pro - Redirect Membership Account
<?php
function pmpro_redirect_account_page_to_login() {
if ( ! is_user_logged_in() ) {
if ( is_page( 'membership-account' ) ) {
$referer = get_permalink( get_queried_object_id() );
$redirect_url = add_query_arg(
array(
'redirect_to' => $referer,
'reauth' => 1,
),
@ronalfy
ronalfy / pmpro-add-user-capability-only.php
Created March 31, 2020 16:49
Paid Memberships Pro - Add User Capability Only
<?php
/**
* Remove capabilities from membership manager role.
*
* @param array $caps Array of capabilities.
*
* @return array new array of capabilities.
*/
function pmpromm_remove_caps( $caps ) {
$caps = array(
@ronalfy
ronalfy / pmpro-hide-discount-code-for-level.php
Last active March 31, 2020 18:41
Paid Memberships Pro - Hide Discount Code for Level
<?php
function my_pmpro_hide_discount_code_for_level( $show ) {
if ( empty( $_REQUEST['level'] ) ) {
return false;
}
if ( 1 === absint( $_REQUEST['level'] ) || 2 === absint( $_REQUEST['level'] ) ) { // 1,2 is the level ID.
return false;
}
return $show;
}
@ronalfy
ronalfy / pmpro-require-vat.php
Created March 31, 2020 17:47
Paid Memberships Pro - Require VAT
<?php
function pmprovat_required_vat_fields_submission( $value ) {
global $pmpro_msg, $pmpro_msgt;
$vat_number = sanitize_text_field( $_REQUEST['vat_number'] );
if ( empty( $vat_number ) ) {
$pmpro_msg = 'VAT is required';
$pmpro_msgt = 'pmpro_error';
}
return $value;
}
@ronalfy
ronalfy / pmpro-login-redirect.php
Last active April 1, 2020 12:52
Paid Memberships Pro - Log In Redirect
<?php
function pmpro_redirect_account_page_to_login() {
if ( ! is_user_logged_in() ) {
$pmpro_pages = array();
$pmpro_pages[] = pmpro_getOption( 'account_page_id' );
$pmpro_pages[] = pmpro_getOption( 'billing_page_id' );
$pmpro_pages[] = pmpro_getOption( 'cancel_page_id' );
$pmpro_pages[] = pmpro_getOption( 'invoice_page_id' );
if ( ! isset( $_REQUEST['level'] ) ) {
$pmpro_pages[] = pmpro_getOption( 'checkout_page_id' );
@ronalfy
ronalfy / pmpro-discount-context.php
Last active April 10, 2020 15:41
Paid Memberships Pro - Discount Context for Code
<?php
function pmpro_add_discount_code_js() {
?>
<script>
jQuery('body').on('DOMSubtreeModified', '#pmpro_level_cost', function(){
setTimeout( function() {
var html = jQuery( '#pmpro_level_cost' ).html();
if ( jQuery( '#pmpro_payment_information_fields' ).is(':visible') == false ) {
jQuery( '.pmpro_discount_code_status' ).html( html );
} else {
@ronalfy
ronalfy / paid-memberships-pro-get-discount-code.php
Last active April 20, 2020 11:30
Paid Memberships Pro - Get Discount Code
<?php
function pmpro_custom_add_discount_code( $atts ) {
if ( function_exists( 'pmprosm_getCodeByUserID' ) && is_user_logged_in() ) {
global $current_user;
$code_id = pmprosm_getCodeByUserID( $current_user->ID ); // Replace $current_user->ID with sponsoree ID.
if ( $code_id ) {
$discount_code = pmprosm_getDiscountCodeByCodeID( $code_id );
if ( isset( $discount_code->code ) ) {
return $discount_code->code;
}