• Resolved PleasantlyOdd

    (@pleasantlyodd)


    Hello,

    I’m trying to use php to add an extra class to an element only if the current users custom role is equal to ‘shopkeeper’.

    __________

    The current class “product_after_shop_loop_switcher”, controls a CSS animation. my aim is to add an extra class called “product_after_shop_loop_switcherOFF”, to turn the animations off.

    __________

    I’ve so far tried something along the lines of

    <div class="product_after_shop_loop_switcher <?php if(in_array('shopkeeper', $current_user->roles)) { return ' product_after_shop_loop_switcherOFF'; } ?>">

    __________

    The basic idea being that if the current user is a shopkeeper, it will return the css string I need and add the class, cancelling out the animations.

    Yet If they are not a shopkeeper, the class will not be added, and the animations will work as normal.

Viewing 1 replies (of 1 total)
  • Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    I resolved this issue with some different code for anyone interested.

    I used:

    <div class="product_after_shop_loop_switcher<?php if( !current_user_can( 'shopkeeper' )){ echo ' product_after_shop_loop_switcherOFF'; } ?>">

    With the above, the product animations are on as default. But if the current user !is not a ‘shopkeeper’, the animations will be disabled.

    _____

    The above assumes your override css sets the animations to none !important;

Viewing 1 replies (of 1 total)
  • The topic ‘Adding CSS classes with PHP, if the users permissions match.’ is closed to new replies.