Skip to content

Instantly share code, notes, and snippets.

@deivamagalhaes
Last active May 14, 2020 19:11
Show Gist options
  • Save deivamagalhaes/e766f35a19995b80ccf1b776aa3a5e92 to your computer and use it in GitHub Desktop.
Save deivamagalhaes/e766f35a19995b80ccf1b776aa3a5e92 to your computer and use it in GitHub Desktop.
Hide checkout add-on from members - replace my-addon with the name of your add-on
<?php
add_filter( 'woocommerce_checkout_add_on_get_enabled', function( $value, $checkout_add_on ) {
// bail if Memberships is not active
if ( ! function_exists( 'wc_memberships_is_user_member' ) ) {
return $value;
}
// if you have more than one checkout add-on, check if it is the one you want to hide
if ( 'my-addon' === $checkout_add_on->get_name() ) {
// return false if user is member of any plan (if you have more plans, you will want to set the 2nd param)
$value = ! wc_memberships_is_user_member();
}
return $value;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment