Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3341799
user inlog see prices without vat
Open

Comments

  • Annette started the conversation

    Hello, do you have an option/plugin who can show the prices to uses who are logged in without vat? 


    Thank you. Annette

  •  767
    Janilyn replied

    Hi Annette,

    Thanks for contacting us here.

    For your information, we do not have any plugin that deals with showing prices without VAT based on user role like that. Our plugins use the price format with or without tax as in the WooCommerce settings of your site only:

    8100185340.png

    Best regards.

    Janilyn T. - WPClever Support Agent

  • Annette replied

    Thank you for your reply. I've found a snipped who does what I want, but it is not working with the prices displayed with Force sell and Frequently Bought Together plugins. Maybe we can change the snipped code a bit to make it work. But I'm not sure what the correct key $ fields are. Can you maybe help me with this? 


    The code: 

    /**
    * Displayed prices excluding taxes for specific user roles
    **/

    add_filter('woocommerce_get_price_html', 'display_prices_excl_taxes_user_role', 100, 2 );
    function display_prices_excl_taxes_user_role( $price_html, $product ) {
        // Here define your user roles in the array
        $targeted_user_roles = array('subscriber', 'administrator');

        $user = wp_get_current_user(); // The WP_User Object

        // For specific user roles (price excluding taxes)
        if ( array_intersect( $user->roles, $targeted_user_roles ) ) {

            // Simple products and products variation
            if( $product->is_type('simple') || $product->is_type('variation') ) {
                if( $product->is_on_sale() ) {
                    $regular_price = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_regular_price() ) );
                    $price_html    = wc_format_sale_price( $regular_price, wc_get_price_excluding_tax( $product ) );
                } else {
                    $price_html = wc_price( wc_get_price_excluding_tax( $product ) );
                }

                $price_html .= $product->get_price_suffix();
            }
            // variable pproducts
            elseif( $product->is_type('variable') ) {
                $prices = $product->get_variation_prices( true );

                if ( ! empty( $prices['price'] ) ) {
                    $act_keys = array_keys($prices['price']);
                    $reg_keys = array_keys($prices['regular_price']);

                    $min_price = wc_get_price_excluding_tax( wc_get_product(current($act_keys)));
                    $max_price = wc_get_price_excluding_tax( wc_get_product(end($act_keys)));

                    $min_reg_price = wc_get_price_excluding_tax( wc_get_product(current($reg_keys)));
                    $max_reg_price = wc_get_price_excluding_tax( wc_get_product(end($reg_keys)));

                    if ( $min_price !== $max_price ) {
                        $price_html = wc_format_price_range( $min_price, $max_price );
                    } elseif ( $product->is_on_sale() && $min_reg_price === $max_reg_price ) {
                        $price_html = wc_format_sale_price( wc_price( $max_reg_price ), wc_price( $min_price ) );
                    } else {
                        $price_html = wc_price( $min_price );
                    }

                    $price_html .= $product->get_price_suffix();
                }
            }
        }
        return $price_html;
    }



  •  767
    Janilyn replied

    Hi Annette,

    I have sent your ticket to one of our developers so that he can help you check that out. 

    It might take some time for him to reach back to you since our developers are not available at the weekend.

    Best regards.

    Janilyn T. - WPClever Support Agent

  • Annette replied

    Hi Janilyn,

    Do you know when I get an update about my ticket from your developers?

    Thank you.

    Annette