Replace product image by a placeholder based on user roles in WooCommerce

霸气de小男生 提交于 2019-12-06 16:00:18

Updated: The following replacement code will handle all product types (even variable products with their variations):

add_filter( 'woocommerce_product_variation_get_image_id', 'woocommerce_product_get_image_id_callback', 10, 2 );
add_filter( 'woocommerce_product_get_image_id', 'woocommerce_product_get_image_id_callback', 10, 2 );
function woocommerce_product_get_image_id_callback( $image_id, $product ) {
    if ( ! ( current_user_can('customer') || current_user_can('administrator') ) ) {
        $image_id = '';
    }
    return $image_id;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!