Skip to content
Advertisement

Need to change product images based on logged in user [closed]

I have some woo-commerce product and i want to change product thumbnail according to different users.

Is there any hook available or other idea?

Advertisement

Answer

Here is what you want to achieves : https://wordpress.org/support/topic/product-image-based-on-user-role/

function woocommerce_product_get_image_id_callback( $image_id, $product ) { 
    $user_id = get_current_user_id();
    
    if ( $user_id = 1 ) {
        $image_id = 23;
    }
    
    return $image_id;
}
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 );
Advertisement