PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Dec 10, 2018 11:37 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Oct 11, 2018 9:06 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4426
Location: United Kingdom
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
   }
}

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 9:44 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4426
Location: United Kingdom
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>'
;
    }
}

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group