Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Created November 10, 2020 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronalfy/183c647a4bb5d9379b7b75ed7a7c30df to your computer and use it in GitHub Desktop.
Save ronalfy/183c647a4bb5d9379b7b75ed7a7c30df to your computer and use it in GitHub Desktop.
PMPro - WooCommerce - Prevent Level from Buying Product
<?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