Last active
October 15, 2024 18:07
-
-
Save somewherewarm-snippets/4f87430a98a15d42995b87ed52e54033 to your computer and use it in GitHub Desktop.
Use this snippet to hide Subscription plans for specific user roles.
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 | |
/** | |
* 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.0 | |
* 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 sw_wc_apfs_filter_schemes( $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; | |
} |
This would be really helpful if it can work correctly as we need to not show any option for subscriptions for our wholesale roles
This worked for me so subscription pricing does not show for our wholesale users (Barn 2 Plugin) -
add_filter( 'wcsatt_product_subscription_schemes', 'sw_wc_apfs_filter_schemes', 10, 2 ):
function sw_wc_apfs_filter_schemes( $schemes, $product ) {
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
// Replace "wcwp_wholesale" with a custom user role.
if ( in_array( 'wcwp_wholesale', $roles ) ) {
$schemes = array();
}
}
return $schemes;
}
That works perfectly! Thank you so much @heidicreative You saved the day!
This worked for me so subscription pricing does not show for our wholesale users (Barn 2 Plugin) - add_filter( 'wcsatt_product_subscription_schemes', 'sw_wc_apfs_filter_schemes', 10, 2 ):
function sw_wc_apfs_filter_schemes( $schemes, $product ) { if( is_user_logged_in() ) { $user = wp_get_current_user(); $roles = ( array ) $user->roles; // Replace "wcwp_wholesale" with a custom user role. if ( in_array( 'wcwp_wholesale', $roles ) ) { $schemes = array(); } }
return $schemes; }
What would I need to do to only show it to wholesale roles?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet is broken currently. The function name referenced in the filter,
apfs_hide_plans_for_specific_user_roles
, is different than the function name given,sw_wc_apfs_filter_schemes
. Can this be updated? Ran across this as a result of 5184806-zen. Thanks!