Skip to content

Instantly share code, notes, and snippets.

@NickGreen
Last active November 22, 2021 02:28
Show Gist options
  • Save NickGreen/80d0ff746fe43da85be5f015a48ccfd4 to your computer and use it in GitHub Desktop.
Save NickGreen/80d0ff746fe43da85be5f015a48ccfd4 to your computer and use it in GitHub Desktop.
Turn off switching for specific user role
<?php
if (is_account_page()) {
$user = wp_get_current_user();
if ( in_array( 'EXAMPLE_ROLE', (array) $user->roles ) ) {
add_filter( 'woocommerce_subscriptions_can_item_be_switched', '__return_false', 100 );
}
}
@Sjakedelic
Copy link

Sjakedelic commented Mar 27, 2019

This is the code we made which works on our site.

        /**
 	* Remove the "Upgrade or Downgrade" button from the My Subscription table if user role is "EXAMPLE_ROLE".
 	*/
	add_filter('woocommerce_subscriptions_switch_link', 'remove_switch_button', 10, 4);
        function remove_switch_button($switch_link, $item_id, $item, $subscription) {
	      $user = wp_get_current_user();
	      if ( in_array( 'EXAMPLE_ROLE', (array) $user->roles ) ) {
		   return '';
	      }
	      return $switch_link;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment