Okay
  Public Ticket #2938728
Show B2C price inc VAT & B2B price ex VAT
Closed

Comments

  •  6
    christian paton started the conversation

    Hi there, I have set a dynamic rule  to show prices ex VAT but adding on to the cart as per the instructions in your docs and that all works great, but my client needs the B2C prices to show inc VAT. I have played with various filters but can't seem to isolate the B2C price and wondered if you could point me in the right direction to achieve this?

    Thanks in advance, chris.

  •  2,218
    WebWizards replied

    I tried writing a snippet:

    add_filter('b2bking_filter_wholesale_price_final', function($price, $text_retail_price, $retail_price, $text_final_price, $b2b_price_price, $product_id){
        $product = wc_get_product($product_id);
        $retail_price = $product->get_price_including_tax();
        $price = '<span class="b2bking_both_prices_text b2bking_retail_price_text">'.$text_retail_price .'</span><span class="b2bking_both_prices_price b2bking_retail_price_price">'. $retail_price . '<br></span><span class="b2bking_both_prices_text b2bking_b2b_price_price">'.$text_final_price.'</span><span class="b2bking_both_prices_price b2bking_b2b_price_price b2bking_b2b_price_id_'.esc_attr($product_id).'">'.$b2b_price_price.'</span>';
        return $price;
    }, 10, 6);
    

    The above should help make the "Retail price" in the "retail price / wholesale price" structure appear to be inc. tax.


    Let me know if that works for you,

    Kind regards,

    Stefan

  •  6
    christian paton replied

    Cheers Stefan, almost perfect. Just had to add "wc_price( $retail_price )" instead of "$retail_price" to the output to add the currency. Thansk again.

    add_filter('b2bking_filter_wholesale_price_final', function( $price, $text_retail_price, $retail_price, $text_final_price, $b2b_price_price, $product_id ){
        $product = wc_get_product($product_id);
        $retail_price = $product->get_price_including_tax();
        $price = '<span class="b2bking_both_prices_text b2bking_retail_price_text">'.$text_retail_price .'</span><span class="b2bking_both_prices_price b2bking_retail_price_price">'. wc_price( $retail_price ) . '<br></span><span class="b2bking_both_prices_text b2bking_b2b_price_price">'.$text_final_price.'</span><span class="b2bking_both_prices_price b2bking_b2b_price_price b2bking_b2b_price_id_'.esc_attr($product_id).'">'. $b2b_price_price .'</span>';
        return $price;
    }, 10, 6);
    
  •  6
    christian paton replied

    Actually I have noticed this works when a variation is selected or pre selected but not when none are, any ideas? I would have thought that it would run through the same filter?

    https://staging8.esmie.co.uk/product/2022-week-to-view-bouquet-spray-dark-blue/

    It's the same for simple products, the RRP should be £3.50  : 

    https://staging8.esmie.co.uk/product/greeting-card-thank-you-white-purple-blossom/

  •   WebWizards replied privately
  •  6
    christian paton replied

    Many thanks Stefan, that seems to do the job, although not sure I fully understand the bit in the middle! I'll post the full function in case someone else wants to use it.

    function b2bking_filter_wholesale_price_final_function( $price, $text_retail_price, $retail_price, $text_final_price, $b2b_price_price, $product_id ){
        $product = wc_get_product($product_id);
        if( $product->is_type('simple') ){
            $retail_price = wc_price( get_post_meta($product_id,'_regular_price', true) );
        } else if( $product->is_type('variable') ){
            $children = $product->get_children();
            $min_price = 0;
            $max_price = 0;
            foreach ($children as $variation_id){
                // get retail price
                $variation = wc_get_product($variation_id);
                $variation_price = get_post_meta($variation_id,'_regular_price', true);
                $variation_price_temp = get_post_meta($variation_id,'_sale_price', true);
                if (!empty($variation_price_temp)){
                    // there is indeed a sale price
                    $variation_price = $variation_price_temp;
                }
                if ($max_price === 0){
                    $min_price = $max_price = $variation_price;
                } else {
                    if ($variation_price < $min_price){
                        $min_price = $variation_price;
                    }
                    if ($variation_price > $max_price){
                        $max_price = $variation_price;
                    }
                }
            }
            // if min and max prices are different, show range, else show the price
            if ($min_price !== $max_price){
                $retail_price = wc_format_price_range( $min_price, $max_price );
            } else {
                $retail_price = wc_price($min_price);
            }
        } else if (is_a($product,'WC_Product_Variation')){
            $retail_price = wc_price( get_post_meta($product_id,'_regular_price', true) );
        }
        
        $price = '<span class="b2bking_both_prices_text b2bking_retail_price_text">'. $text_retail_price .'</span><span class="b2bking_both_prices_price b2bking_retail_price_price">' . $retail_price . '<br></span><span class="b2bking_both_prices_text b2bking_b2b_price_price">'.$text_final_price.'</span><span class="b2bking_both_prices_price b2bking_b2b_price_price b2bking_b2b_price_id_' . esc_attr($product_id) .'">'. $b2b_price_price .'</span>';
        return $price;
    }
    add_filter( 'b2bking_filter_wholesale_price_final', 'b2bking_filter_wholesale_price_final_function', 10, 6 );
    
  •  2,218
    WebWizards replied

    I took the middle portion from the regular B2BKing function, but I deleted the code that adjusts for tax, so it's the price incl. tax.

    What it does is: it gets all children (all variations) of the main variable product, and goes through them to find the minimum price and the maximum price.

    If the minimum is the same as the maximum (all variations have the same price), then we simply show that price. Otherwise, we show the price range (format range function). In your case, there's the snippet we previously discussed that makes the range look like "From: Min" instead of the typical "min - max" display.

    If you have any questions about how the code works, let me know. I enjoy explaining it, but no one ever asks me about itsmile.png

  •  6
    christian paton replied

    Ah ok, that makes sense, thanks. 

    Ha ha, well that's handy as I like to know how it works if I can, so I can change it myself if need be. 

  • DBKCURK replied

    I bought this plugin for one simple function. Show incl. VAT for normal customers and show excl. VAT for B2B customers. 

    Is there a simple howto? Or is this the wrong plugin for that?

    All the other things on our shop are allready up and running including 2 customer groups. 

  •  2,218
    WebWizards replied

    Hi there,

    Please see our guide here for that: https://woocommerce-b2b-plugin.com/docs/how-to-display-prices-excluding-tax-for-b2b-users-and-including-tax-for-b2c-users/

    In short, what you want to do is to have a normal tax setup in the site, and then go to B2BKing -> Dynamic Rules and create a "Tax Exemption" rule for your B2B customers.

    We'd be happy to assist you with this if needed - if so, please open a separate dedicated ticket.

    Kind regards,

    Stefan