I'm developing a woocommerce website and would appreciate some help regarding an issue I am facing.
I have already set up 2 new user roles (Silver, Gold) and adjust the prices accordingly. So far so good.
What I want now is the ability of showing some of the product images only for those 2 new roles I've added. Not to the default customers.
Is this somehow possible? I've searched for a plugin that could do the job but couldn't find one. I also tried building the below custom function but could not find out how to distinct showing/hidden images.
function img_by_user_role {
$user = wp_get_current_user();
$allowed_roles = array('silver', 'gold');
<?php if( array_intersect($allowed_roles, $user->roles ) ) { ?>
//stuff here for allowed roles
<?php } ?>
Any help would be very much appreciated, thank you for your time..
As 'mrhossen' suggested I was able to solve the problem using ACF plugin.
For anyone who may face the same problem, this is how I managed to do so.
<?php if( current_user_can('silver') || current_user_can('gold') ) {
$image = get_field('image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; } ?>
Thanks again for your help, much appreciated!