Created
July 11, 2024 08:00
-
-
Save dwanjuki/775d7b0d44f7a352f534bbe78e1ba487 to your computer and use it in GitHub Desktop.
Exclude some membership level purchases from PMPro Affiliate tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Exclude some membership level purchases from PMPro Affiliate tracking | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_affiliates_tracking_exclude_levels( $order ){ | |
if( ! function_exists( 'pmpro_affiliates_pmpro_added_order' ) ) { | |
return; | |
} | |
// checkout level IDs to exclude from affiliate tracking | |
$exclude_levels = array( 1, 2 ); | |
$pmpro_level = $order->getMembershipLevel(); | |
if ( in_array( $pmpro_level->id, $exclude_levels ) ) { | |
remove_action( 'pmpro_added_order', 'pmpro_affiliates_pmpro_added_order' ); | |
remove_action( 'pmpro_after_checkout', 'pmpro_affiliates_no_order_checkout' ); | |
} | |
} | |
add_action( 'pmpro_added_order', 'my_pmpro_affiliates_tracking_exclude_levels', 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment