Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / irishhealer_adjust_price_pmprorh_init.php
Created February 21, 2018 19:49
Custom Register Helper fields for Irishhealer thread on price-adjusting fields.
<?php
/**
* Custom Register Helper fields for Irishhealer thread on price-adjusting fields.
*/
function irishhealer_adjust_price_pmprorh_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
@kimcoleman
kimcoleman / count_transation_ids.php
Created February 23, 2018 00:42
Count the number of times a subscription ID has processed in total with each added order.
<?php
/**
* Count the number of times a subscription ID has processed in total with each added order.
*/
function count_transation_ids( $MemberOrder ) {
global $wpdb;
$orders = $wpdb->get_results("SELECT o.*, UNIX_TIMESTAMP(o.timestamp) as timestamp, l.name as membership_level_name FROM $wpdb->pmpro_membership_orders o LEFT JOIN $wpdb->pmpro_membership_levels l ON o.membership_id = l.id WHERE o.user_id = '$MemberOrder->user_id' AND o.subscription_transaction_id = '$MemberOrder->subscription_transaction_id' ORDER BY timestamp DESC");
$orders_count = count( $orders );
}
add_action( 'pmpro_added_order', 'count_transation_ids' );
@kimcoleman
kimcoleman / remove_woocommerce_account_menu_items.php
Created February 23, 2018 11:56
Remove some links from the WooCommerce My Account sidebar navigation if user is level 4.
<?php
/**
* Remove some links from the WooCommerce My Account sidebar navigation if user is level 4.
*
* @param array $endpoints The array of items in the account menu.
*/
function remove_woocommerce_account_menu_items( $endpoints ) {
$level = pmpro_getMembershipLevelForUser();
if ( esc_attr( $level->ID ) === '4' ) {
unset( $endpoints['edit-account'] );
@kimcoleman
kimcoleman / remove_woocommerce_account_content.php
Last active November 30, 2020 00:26
Remove the welcome message from the WooCommerce My Account page.
<?php
/**
* Remove the welcome message from the WooCommerce My Account page.
*/
function remove_woocommerce_account_content() {
if ( function_exists( 'pmpro_getMembershipLevelForUser' ) ) {
$level = pmpro_getMembershipLevelForUser();
if ( esc_attr( $level->ID ) === '4' ) {
remove_action( 'woocommerce_account_content', 'woocommerce_account_content' );
}
@kimcoleman
kimcoleman / irishhealer_pmprorh_init.php
Created February 27, 2018 19:21
Register Helper custom fields for irishhealer.
<?php
/**
* Register Helper custom fields for irishhealer.
*/
function irishhealer_pmprorh_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
@kimcoleman
kimcoleman / fire_fb_pixel_nvujnich.php
Last active February 28, 2018 18:16
Fire Facebook Pixel on second order
<?php
/*
* Fire Facebook Pixel on second order
*/
function fire_fb_pixel( $MemberOrder ) {
global $wpdb;
$orders = $wpdb->get_results("SELECT o.*, UNIX_TIMESTAMP(o.timestamp) as timestamp, l.name as membership_level_name FROM $wpdb->pmpro_membership_orders o LEFT JOIN $wpdb->pmpro_membership_levels l ON o.membership_id = l.id WHERE o.user_id = '$MemberOrder->user_id' AND o.subscription_transaction_id = '$MemberOrder->subscription_transaction_id' ORDER BY timestamp DESC");
$transactionCount = count( $orders );
if( $transactionCount == 2 ) {
@kimcoleman
kimcoleman / insert_pmpro_member_profile_shortcode_tourism.php
Created March 2, 2018 12:27
Custom recipe to add the [pmpro_member_profile] to your bbPress user profile page for forum thread.
<?php
/**
* Use this recipe to add the [pmpro_member_profile] to your bbPress user profile page.
*/
function insert_pmpro_member_profile_shortcode() {
$user_id = bbp_get_user_id( 0, true, false );
echo do_shortcode( '[pmpro_member_profile fields="Company,company; Industry sector,tourism_sector; Region,tourism_region;Country,pmpro_bcountry;Website,user_url" show_bio="true" show_email="true" show_level="false" show_startdate="false" show_avatar="false" user_id="' . $user_id . '"]' );
}
add_action( 'bbp_template_before_user_profile', 'insert_pmpro_member_profile_shortcode', 15, 0 );
@kimcoleman
kimcoleman / choose_specific_level_for_addon_packages
Last active April 12, 2021 20:25
Tell PMPro and PMPro Add On Packages to use the user's current level or a specific level by ID when checking out for an Addon package.
/**
* Use new pmproap_text_level_id filter to choose the user's currenet level OR a specific level with access.
* Update this code as needed and add to a custom plugin.
*/
function choose_specific_level_for_addon_packages( $text_level_id, $post_id, $user_id, $post_levels ) {
if ( ! pmpro_hasMembershipLevel( $text_level_id, $user_id ) && in_array( 8, $post_levels ) ) {
$text_level_id = 8;
}
return $text_level_id;
@kimcoleman
kimcoleman / my_pmpro_rh_custom_fields_maxk97.php
Created March 8, 2018 10:37
Another take on the custom fields for maxk97
<?php
/**
* Custom Fields for various sections of checkout
*/
function my_pmpro_rh_custom_fields() {
global $current_user;
// don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
@kimcoleman
kimcoleman / elementor_compatibility_for_pmpro.php
Last active October 26, 2023 08:40
Ensure Paid Memberships Pro compatibility when using the Elementor Page Builder.
<?php
/**
* Ensure Paid Memberships Pro compatibility when using the Elementor Page Builder:
* https://wordpress.org/plugins/elementor/
*
* Your administrator-level account must have a Membership Level in order to edit all of the pages assigned
* under Memberships > Pages.
*
* You must also set a Custom Field on the Membership Checkout page with the key 'pmpro_default_level' and
* value of a level ID in order to properly edit your Membership Checkout page using Elementor.