• Resolved ciberdom

    (@ciberdom)


    Hello everyone

    In my online store there are three types of users and I need to show the tax according to the User Role. All users have the same tax, 21% VAT.

    Users “customer” and “guest”
    Show the prices of the products with the tax included.

    “Partner” users
    Show the prices of the products without the tax. The tax must appear separately.

    After trying several plugins I found in this forum the help of a code that can solve the problem but strangely adds a few lines of text that I do not understand.

    Code:

    `add_filter(‘pre_option_woocommerce_tax_display_shop’, ‘alter_tax_display’);
    add_filter(‘pre_option_woocommerce_tax_display_cart’, ‘alter_tax_display’);

    function alter_tax_display( $tax_display ) {
    if (current_user_can(“mayorista”)){
    return “excl”;
    } else {
    return “incl”;
    }
    }

    add_filter( ‘woocommerce_get_price_suffix’, ‘wc_get_price_suffix_filter’, 10, 2 );
    function wc_get_price_suffix_filter( $price_display_suffix, $item, $cart ) {
    // check for the user role return blank if it matches
    if (current_user_can(“mayorista”))
    $price_display_suffix = ‘<span class=”sufijomayoristas”>(+ IVA)</span>’;

    return $price_display_suffix;
    }

    Text lines after applying the code:
    https://vegan-tattoo.com/wp-content/uploads/02-a.jpg

    Warnings:
    I am using the “WooCommerce Dynamic Pricing” plugin to configure different prices according to User Roles. As can be seen in the image, the product has a different price according to the User Role.

    Please, any help would be fantastic.
    Thanks in advance

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @ciberdom,

    In this line of code:

    
    add_filter( ‘woocommerce_get_price_suffix’, ‘wc_get_price_suffix_filter’, 10, 2 );
    

    number 2 at the end means how many arguments – different parameters will be passed to the function changing price suffix. However, in the next line you create the function like:

    
    function wc_get_price_suffix_filter( $price_display_suffix, $item, $cart ) {
    

    It expects three arguments: $price_display_suffix, $item, and $cart. The last one is missing and so it results in an error.

    To get this fixed, please try to replace this line with:

    
    function wc_get_price_suffix_filter( $price_display_suffix, $item ) {
    

    This way the function will expect 2 arguments and the problem should be no more.

    Cheers!

    Thread Starter ciberdom

    (@ciberdom)

    Hello @madeincosmos;

    Thank you very much for the response and the fantastic help. Before your answer I got help from one of your colleagues through the chat. Finally I added the following code and it seems to be working correctly. I’ve been trying for a few days to see if there are no problems. I’ll tell you how things are going.

    Code:

    add_filter(‘pre_option_woocommerce_tax_display_shop’, ‘alter_tax_display’);
    add_filter(‘pre_option_woocommerce_tax_display_cart’, ‘alter_tax_display’);

    function alter_tax_display( $tax_display ) {
    if ( current_user_can( “partner” ) ){
    return “excl”;
    } else {
    return “incl”;
    }
    }

    add_filter( ‘woocommerce_get_price_suffix’, ‘wc_get_price_suffix_filter’, 10, 2 );
    function wc_get_price_suffix_filter( $price_display_suffix, $item ) {
    // check for the user role return blank if it matches
    if ( current_user_can( “partner” ) ) {
    $price_display_suffix = ‘<span class=”sufijopartner”>(+ IVA)</span>’;
    }

    return $price_display_suffix;
    }

    madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @ciberdom,

    Thanks a lot for letting me know, I’m really glad to hear this snippet helped!

    I’ll mark this thread as resolved for now. If you have any additional questions, feel free to start a new one.

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Different tax according to the User Role (Code)’ is closed to new replies.