Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimcoleman/8ee7d9150c1a3feeb63b03170f3da761 to your computer and use it in GitHub Desktop.
Save kimcoleman/8ee7d9150c1a3feeb63b03170f3da761 to your computer and use it in GitHub Desktop.
Examples for how to hide the banners based on the user's EDD purchase history or role.
<?php
/**
* Examples for how to hide the banners based on the user's EDD purchase history.
*/
function my_swsales_show_banner_exclude_users_edd_examples( $show_banner, $active_sitewide_sale ) {
// Return early if there is no logged in user.
if ( ! is_user_logged_in( ) ) {
return $show_banner;
}
// Get the current user object.
$user = wp_get_current_user();
// Check if user purchased a specific download.
if ( function_exists( 'edd_has_user_purchased' ) && edd_has_user_purchased( $user->ID, '705' ) && ! current_user_can( 'manage_options') ) {
$show_banner = false;
}
// Check if user has purchased any downloads.
if ( function_exists( 'edd_has_purchases' ) && edd_has_purchases( $user->ID ) && ! current_user_can( 'manage_options') ) {
$show_banner = false;
}
return $show_banner;
}
add_filter( 'swsales_show_banner', 'my_swsales_show_banner_exclude_users_edd_examples', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment