Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Last active June 28, 2022 06:12
Show Gist options
  • Select an option

  • Save goranefbl/009efef5ce0a2346566b4fc414301e92 to your computer and use it in GitHub Desktop.

Select an option

Save goranefbl/009efef5ce0a2346566b4fc414301e92 to your computer and use it in GitHub Desktop.
WPGens WooCommerce Membership
add_filter('wpgens_raf_code','gens_raf_code',10,1);
function gens_raf_code($raf_code) {
$user_id = get_current_user_id();
$args = array(
'status' => array( 'active', 'complimentary', 'pending' ),
);
if(!function_exists('wc_memberships_get_user_memberships')) {
return $raf_code;
}
$active_memberships = wc_memberships_get_user_memberships( $user_id, $args );
if ( empty( $active_memberships ) ) {
return 'Referral code is available only to users with Membership';
}
return $raf_code;
}
add_filter('wpgens_raf_link','gens_raf_link',10,3);
function gens_raf_link($raf_link, $referral_id, $type) {
$user_id = get_current_user_id();
$args = array(
'status' => array( 'active', 'complimentary', 'pending' ),
);
if(!function_exists('wc_memberships_get_user_memberships')) {
return $raf_link;
}
$active_memberships = wc_memberships_get_user_memberships( $user_id, $args );
if ( empty( $active_memberships ) ) {
return 'Referral link is available only to users with Membership';
}
return $raf_link;
}
add_action('wp','wpgens_custom_account_tabs');
function wpgens_custom_account_tabs(){
$user_id = get_current_user_id();
$args = array(
'status' => array( 'active', 'complimentary', 'pending' ),
);
if(!function_exists('wc_memberships_get_user_memberships')) {
return;
}
$active_memberships = wc_memberships_get_user_memberships( $user_id, $args );
if ( empty( $active_memberships ) ) {
$gens_plugin = WPGens_RAF::instance();
remove_filter( 'woocommerce_account_menu_items', array($gens_plugin->my_account,'gens_account_menu_item'),10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment