Droid Genie
Droid Genie

Reputation: 361

Change SALE Tag Based on user role in WooCommerce

I want to Change the SALE Tag for SALE price products based on user role in WooCommerce. For example, someone with an editor role will see "SALE PRICE FOR EDITOR" whereas someone with a customer role will see "SALE PRICE FOR CUSTOMER"

What I mean by the SALE tag is the text that is displayed above the product image when the sale price is turned on.

Upvotes: 0

Views: 101

Answers (1)

Cray
Cray

Reputation: 5493

this code should work:

add_filter('woocommerce_sale_flash', 'change_sale_text');
function change_sale_text() {
    $user = wp_get_current_user();
    if ( in_array( 'editor', (array) $user->roles ) ) {
        return '<span class="onsale">SALE PRICE FOR EDITOR</span>';
    } elseif ( in_array( 'customer', (array) $user->roles ) ) {
        return '<span class="onsale">SALE PRICE FOR CUSTOMER</span>';
    } else {
        return '<span class="onsale">SALE</span>';
    }
}

Upvotes: 1

Related Questions