Home / eCommerce / Custom Tax Display Settings for Regular Prices by Specific Wholesale Roles
Duplicate Snippet

Embed Snippet on Your Site

Custom Tax Display Settings for Regular Prices by Specific Wholesale Roles

This code snippet will be applied to simple products on the single product page only

Code Preview
php
<?php
// Display regular price excluding tax for specific user role
add_filter('woocommerce_get_price_html', 'custom_display_regular_price_ex_tax_for_role', 100, 2);
function custom_display_regular_price_ex_tax_for_role($price_html, $product) {
    // Only run on frontend and for logged-in users
    if (is_admin() || !is_user_logged_in()) return $price_html;
    // Get current user and their roles
    $user = wp_get_current_user();
    if (!in_array('vip_wholesale', (array) $user->roles)) return $price_html;
    // For simple products
    if ($product->is_type('simple')) {
        $regular_price = $product->get_regular_price();
        $price_ex_tax = wc_get_price_excluding_tax($product, ['price' => $regular_price]);
        return wc_price($price_ex_tax) . ' <small>(ex GST)</small>';
    }
    return $price_html;
}

Comments

Add a Comment