Last active
June 8, 2022 15:45
-
-
Save kimcoleman/664b52134f5909f6d920ef1ed012a631 to your computer and use it in GitHub Desktop.
Show WooCommerce Store Notice to Logged In Previous Customers Only.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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