Created
November 10, 2020 16:51
-
-
Save ronalfy/183c647a4bb5d9379b7b75ed7a7c30df to your computer and use it in GitHub Desktop.
PMPro - WooCommerce - Prevent Level from Buying Product
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 | |
/** | |
* Prevent certain levels from purchasing products. | |
* Change the `12` below to othe level you'd like to hide. | |
* | |
* 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 pmpro_stop_level_members_from_buying_woo( $is_purchasable, $product ) { | |
// Check if the user has an active membership level. | |
if ( pmpro_hasMembershipLevel( 12 ) || ! is_user_logged_in() ) { | |
return false; | |
} | |
return $is_purchasable; | |
} | |
add_filter( 'woocommerce_is_purchasable', 'stop_non_pmpro_members_from_buying_woo', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment