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-bulgarian-currency.php
Created June 29, 2020 17:36
Paid Memberships Pro - Bulgarian Currency
<?php
// Adds the BGN currency to currency list.
function pmpro_currencies_bulgarian( $currencies ) {
$currencies['BGN'] = __( 'Bulgarian', 'pmpro' );
return $currencies;
}
add_filter( 'pmpro_currencies', 'pmpro_currencies_bulgarian' );
@ronalfy
ronalfy / pmpro-ms-redirect.php
Created June 2, 2020 16:26
Paid Memberships Pro - Multisite Redirect
<?php
function pmpro_multisite_subsite_custom_redirect() {
if ( is_main_site() || is_admin() ) {
return;
}
if ( function_exists( 'pmpro_hasMembershipLevel' ) ) {
global $current_user;
if ( 0 == $current_user->ID || ! pmpro_hasMembershipLevel() ) {
wp_redirect( get_site_url( 1, '/membership-account/membership-levels/' ) ); // Assume main site ID is 1.
exit;
@ronalfy
ronalfy / pmpro-ban-email-domains.php
Created May 28, 2020 12:42
Paid Memberships Pro - Ban Email Domains
<?php
function pmpro_custom_banned_domains( $continue_registration ) {
global $pmpro_msg, $pmpro_msgt;
if ( isset ( $_REQUEST['bemail'] ) ) {
$bemail = sanitize_email( stripslashes( $_REQUEST['bemail'] ) );
$banned_email_domains = array(
'.ru', /* Add more email domains here */
);
foreach ( $banned_email_domains as $domain ) {
if ( strstr( $bemail, $domain ) ) {
@ronalfy
ronalfy / pmpro-show-content-list.php
Created April 30, 2020 16:22
Paid Memberships Pro - Show Content List
<?php
/**
* Show pages/posts a level/user has access to.
*
* @param array $atts Shortcode attributes.
*
* @return string HTML for the post list.
*/
function member_content_list( $atts ) {
if ( ! is_user_logged_in() ) {
@ronalfy
ronalfy / pmpro-add-fields-checkout-send-data-zapier.php
Last active October 24, 2024 06:41
Paid Memberships Pro - Add Fields to Checkout and Pass Data to Zapier
<?php
function my_pmprorh_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// Define the fields.
$fields = array();
$fields[] = new PMProRH_Field(
@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;
}
@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 / 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-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-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;
}