PHP Developers Network
http://forums.devnetwork.net/

Wordpress: can this be altered based on user type for CSS?
http://forums.devnetwork.net/viewtopic.php?f=1&t=147866
Page 1 of 1

Author:  simonmlewis [ Thu Oct 11, 2018 9:06 am ]
Post subject:  Wordpress: can this be altered based on user type for CSS?

We are trying to show some CSS only when someone is a) logged in and their usertype is 'wholesaler'.

This function should set the CSS for us, but for all.

The idea is to switch off a 'rotating' price area, and just show the price and wholesale price to wholesaler users.
with it turned on, there is a big gap where the code is setting it to be a fixed height. If I disabled the fixed height, when logged in as wholesaler, the Price below the wholesale title disappears.

Syntax: [ Download ] [ Hide ]
add_action('wp_head', 'add_css_head');
function add_css_head() {
   if ( is_user_logged_in() ) {
   ?>
      <style>

.wholesale_price_container
{
    line-height: 20px;
}

.grve-product-item .grve-product-content {    
    overflow: visible;
    height: 65px;
}
.grve-product-item .hover .grve-product-switcher,
.grve-product-item .grve-product-switcher.product-added {
 -webkit-transform: none;
 -moz-transform:    none;
 -ms-transform:     none;
 -o-transform:      none;
 transform:         none;
}
      </style>
   <?php
   }
}

Author:  simonmlewis [ Thu Oct 11, 2018 9:44 am ]
Post subject:  Re: Wordpress: can this be altered based on user type for CS

As often happens, I found a fix myself.
This CSS will work for any type of user role within Wordpress, and means you can override the CSS based on that role.

I had to double check the user role wording in the database, and use "!important", to override any existing CSS.

Syntax: [ Download ] [ Hide ]
// set wholesale CSS overrides.
// includes setting category pages wholesale price box to disable rollover, while keeping the setting for non-wholesalers
add_action( 'wp_enqueue_scripts', 'set_wholesale_css' );
function set_wholesale_css(){
    if( in_array( 'wholesale_customer', (array) wp_get_current_user()->roles ) ){
        echo '<style>
        .grve-add-to-cart-btn
        {
        display: none!important;
        }

        .wholesale_price_container
        {
        line-height: 20px!important;
        }

        .grve-product-item .grve-product-content
        {
        overflow: visible!important;
        height: 65px!important;
        }
       
        .grve-product-item .hover .grve-product-switcher,
        .grve-product-item .grve-product-switcher.product-added {
        -webkit-transform: none!important;
        -moz-transform:    none!important;
        -ms-transform:     none!important;
        -o-transform:      none!important;
        transform:         none!important;
        }
      </style>'
;
    }
}

Author:  Vegan [ Mon Feb 18, 2019 1:54 pm ]
Post subject:  Re: Wordpress: can this be altered based on user type for CS

I use custom CSS on my gaming site which is supported by the Theme I use

never considered more than that as I prefer to have my site as fast as possible due to the traffic load

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/