• Hello, my client uses 2 custom user roles (VOC1 and VOC2). I am using prices based on user role modules, where is the multiplier set to 0.58 for VOC1 and 0.75 for VOC2.

    Now my client would like to give the sale price for some products for basic users (without VOC1 nor VOC2), but prices for custom roles are now calculated from sale price. Is possible to set somehow, prices for VOC1 and VOC2 will be ALWAYS calculated from regular price, regardless the sale price of product?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support David G

    (@gravid7)

    Hi @lavadesign

    Thanks for reaching out to us.

    If possible can you please share screenshots of your configuration settings and screenshots of your issue? So, we can check and help you.

    Hello, thanks for reply. However, meanwhile I have solved this issue with a help of AI. This is code, that works for me:

    // custom discounts by user role
    function custom_role_based_price( $price, $product ) {
        $user = wp_get_current_user();
        $user_role = $user->roles[0]; // Získání role prvního p?i?azeného u?ivateli
        $apply_to_sale_price = false; // True, pokud se sleva aplikuje na slevovou cenu, False pro p?vodní cenu
        // Kontrola, zda u?ivatel má specifickou roli
        if ( $user_role === 'voc2' ) { // Nahra?te 'role_slug' za slug po?adované role
            
    
            if ( $apply_to_sale_price && $product->is_on_sale() ) {
                $price = $product->get_sale_price() * 0.65; // Sleva na slevovou cenu (10% sleva)
            } else {
                $price = $product->get_regular_price() * 0.65; // Sleva na p?vodní cenu (10% sleva)
            }
        }
    
        if ( $user_role === 'voc1' ) { // Nahra?te 'role_slug' za slug po?adované role
    
            if ( $apply_to_sale_price && $product->is_on_sale() ) {
                $price = $product->get_sale_price() * 0.75; // Sleva na slevovou cenu (10% sleva)
            } else {
                $price = $product->get_regular_price() * 0.75; // Sleva na p?vodní cenu (10% sleva)
            }
        }
    
        return $price;
    }
    add_filter( 'woocommerce_product_get_price', 'custom_role_based_price', 10, 2 );

    My custom roles is named “voc1” and “voc2”.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Price by user roles always calculated from regular price’ is closed to new replies.