Skip to content

Instantly share code, notes, and snippets.

@messica
messica / generate-discount-code-pmpro.php
Last active May 23, 2019 16:08 — forked from andrewlimaza/generate-discount-code-pmpro.php
Generate a discount code for Paid Memberships Pro (with Subscription Delay)
<?php
/**
* Generate a discount code for Paid Memberships Pro. Call this function whenever you'd like to generate a new discount code.
* Adjust the code accordingly for discount uses and level settings for the discount code.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
* www.paidmembershipspro.com
*/
@messica
messica / custom_taxonomy_rh_field.php
Created May 16, 2019 16:38
Register Helper example: custom taxonomy select2 field
<?php
// Get custom taxonomy terms.
$cause_categories = get_terms( array(
'taxonomy' => 'cause-category',
) );
$options = array();
foreach ( $cause_categories as $key => $category ) {
$options[$category->term_id] = $category->name;
@messica
messica / my_pmprowoo_plugins_loaded.php
Created May 10, 2019 16:46
Allow multiple membership products to be purchased.
<?php
/**
* Allow multiple membership products to be purchased.
*/
function my_pmprowoo_plugins_loaded() {
remove_filter( 'woocommerce_is_purchasable', 'pmprowoo_is_purchasable', 10, 2 );
}
add_action( 'plugins_loaded', 'my_pmprowoo_plugins_loaded' );
@messica
messica / my_pmpro_login_redirect_url.php
Last active May 14, 2019 18:48
Redirect on login if user has any failed payments. (Requires Paid Memberships Pro Failed Payment Limit Add On)
<?php
/**
* Redirect on login if user has any failed payments. (Requires Paid Memberships Pro Failed Payment Limit Add On)
*/
function my_pmpro_login_redirect_url( $url, $request, $user ) {
// Set failed payment redirect URL here.
$failed_payment_redirect_url = site_url( 'payment-failed' );
@messica
messica / my_woocommerce_order_status_completed.php
Created April 30, 2019 00:49
Sync new members purchased through WooCommerce with MailChimp
<?php
/**
* Sync new members purchased through WooCommerce with MailChimp
*/
function my_woocommerce_order_status_completed() {
if ( function_exists( 'pmpromc_processSubscriptions' ) ) {
pmpromc_processSubscriptions();
}
}
@messica
messica / my_the_content.php
Created April 30, 2019 00:15
Hide non-member messages on category archives.
<?php
/**
* Hide non-member messages on category archives.
*/
function my_the_content( $content ) {
if ( is_category() ) {
$content = preg_replace( '/<div class="pmpro_content_message">.*<\/div>/', '', $content );
}
return $content;
@messica
messica / my_pmprolpv_has_membership_access.php
Created April 25, 2019 16:46
Limit Post Views: Don't allow post views for certain categories.
<?php
/**
* Limit Post Views: Don't allow post views for certain categories.
*/
function my_pmprolpv_has_membership_access( $has_access, $post ) {
// Set blocked categories here.
$blocked_categories = array( 'silver', 'gold' );
@messica
messica / my_avf_append_burger_menu_location.php
Created April 11, 2019 00:45
Always append burger menu items. (Fix for PMPro Nav Menus with Avada themes)
<?php
// Always append burger menu items. (Fix for PMPro Nav Menus with Avada themes)
function my_avf_append_burger_menu_location($location, $original_location, $items, $args) {
return $original_location;
}
add_filter('avf_append_burger_menu_location', 'my_avf_append_burger_menu_location', 10, 4);
@messica
messica / pmpro-customizations.php
Last active April 11, 2019 20:32
Add language switcher to new site form. (Member Network Sites)
<?php
/**
* Change new site language based on language switcher.
*/
function my_pmpro_network_new_site( $blog_id, $user_id ) {
if ( ! empty( $_REQUEST['WPLANG'] ) ) {
switch_to_blog( $blog_id );
update_option( 'WPLANG', sanitize_text_field( $_REQUEST['WPLANG'] ) );
restore_current_blog();
@messica
messica / my_pmpro_authorizenet_post_url.php
Created April 3, 2019 17:34
Use BNG Gateway Emulator post URL for Authorize.net gateway
<?php
/**
* Use BNG Gateway Emulator post URL for Authorize.net gateway
*/
function my_pmpro_authorizenet_post_url($url) {
return 'https://secure.bngpaymentgateway.com/gateway/transact.dll';
}
add_filter('pmpro_authorizenet_post_url', 'my_pmpro_authorizenet_post_url');