Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/664b52134f5909f6d920ef1ed012a631 to your computer and use it in GitHub Desktop.
Save kimcoleman/664b52134f5909f6d920ef1ed012a631 to your computer and use it in GitHub Desktop.
Show WooCommerce Store Notice to Logged In Previous Customers Only.
<?php
/**
* Show WooCommerce Store Notice to Logged In Previous Customers Only.
*/
function modify_woocommerce_demo_store_customers_only( $notice_html ) {
if ( ! is_user_logged_in() ) {
return '';
}
// Get the user object.
$user = get_userdata( get_current_user_id() );
// Get all the user roles as an array.
$user_roles = $user->roles;
// Check if the role you're interested in is present in the array.
if ( ! in_array( 'customer', $user_roles, true ) ) {
$notice_html = '';
}
return $notice_html;
}
add_filter( 'woocommerce_demo_store', 'modify_woocommerce_demo_store_customers_only', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment