Skip to content

Instantly share code, notes, and snippets.

@woogists
Created August 20, 2025 20:00
Show Gist options
  • Save woogists/28ad7aefadac555baca1bc296f69b794 to your computer and use it in GitHub Desktop.
Save woogists/28ad7aefadac555baca1bc296f69b794 to your computer and use it in GitHub Desktop.
[All Products for WooCommerce Subscriptions] Use this snippet to hide Subscription plans for specific user roles.
<?php
/**
* Plugin Name: All Products for WooCommerce Subscriptions - Hide Subscription plans for specific user roles.
* Plugin URI: https://woocommerce.com/products/all-products-for-woocommerce-subscriptions/
* Description: Use this snippet to hide Subscription plans for specific user roles.
* Version: 1.1
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Developer: Jason Kytros
*
* Copyright: © 2021 Automattic.
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_filter( 'wcsatt_product_subscription_schemes', 'apfs_hide_plans_for_specific_user_roles', 10, 2 );
function apfs_hide_plans_for_specific_user_roles( $schemes, $product ) {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = (array) $user->roles;
// Replace "administrator" with a custom user role.
if ( in_array( 'administrator', $roles ) ) {
$schemes = array();
}
}
return $schemes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment