I would like that only the user role 'customer' see the product images and all the other roles see a default product image.
I am searching to do this with no luck. Can someone help me please?
I managed to do the same for the product prices and this is working correctly
The code I added to functions.php is:
function ace_hide_prices_guests( $price ) {
if(current_user_can('customer')) {
return $price;
}
return '';
}
add_filter( 'woocommerce_get_price_html', 'ace_hide_prices_guests' );
Thanks
I would like that only the user role 'customer' see the product images and all the other roles see a default product image.
I am searching to do this with no luck. Can someone help me please?
I managed to do the same for the product prices and this is working correctly
The code I added to functions.php is:
function ace_hide_prices_guests( $price ) {
if(current_user_can('customer')) {
return $price;
}
return '';
}
add_filter( 'woocommerce_get_price_html', 'ace_hide_prices_guests' );
Thanks
Share Improve this question edited Apr 1, 2019 at 9:03 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Apr 1, 2019 at 8:53 Kevin SneyersKevin Sneyers 31 bronze badge 2 |1 Answer
Reset to default 0/**
* Only allowing the customer and admin user role to view the product images
*
* @param $value
*
* @return bool
*/
function woocommerce_product_get_image_id_callback( $value ) {
global $current_user;
if (
in_array( 'customer', (array) $current_user->roles )
|| in_array( 'administrator', (array) $current_user->roles )
) {
return $value;
} else {
return false;
}
}
add_filter( 'woocommerce_product_get_image_id', 'woocommerce_product_get_image_id_callback', 10, 1 );
Copy the above code and paste it into you functions.php file of your child themes
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745637242a4637468.html
|| is_admin()
on all of these checks. – Rup Commented Apr 1, 2019 at 9:44