Public Ticket #3045451

Margin calculator

Closed
Comments
3 Tickets 1
Anthony Chadburn started the conversation 4 years ago on May 17, 2022 at 8:28am

Hello,

I need on product page a margin calculator.

Exemple :

Your price : 50€

Recommanded public price : 70€

Your margin : 20€ (40%)

Is it possible to do that with BBKing ?

Best

2,762
KingsPlugins replied 4 years ago on May 17, 2022 at 9:57am

Hi there,

Thank you for getting in touch - I think we replied to your email a short while ago,

As I mentioned there: 

-> It's possible to display the retail price to B2B users (this way wholesalers can see both their price, and the retail price for that same product). More info at https://b2bkingplugin.com/docs/how-to-display-rrp-recommended-retail-price-to-b2b-users/

image-1-2048x833.png

However, there's no feature to also show the margin there.

There is however a custom information table feature - perhaps that can be useful:

-> For each product you can also set up a custom information table: https://b2bkingplugin.com/docs/custom-information-table-in-product-page/ . Here you can enter any information that you want, such as wholesaler margin. You can set up a different information table for each group / category of users - that way, business users can see a different table than retail users.

Kind regards,

Stefan

3 Tickets 1
Anthony Chadburn replied 4 years ago on May 17, 2022 at 3:05pm

Thanks for your answer. I updated the file 

public/class-b2bking-public.php

How can i put my updates in my function.php:9238 ?

                           $wholesale_price = apply_filters('b2bking_filter_wholesale_price', $wholesale_price, $product_id);

$margin=100-round(preg_replace("/([^0-9\\.])/i", "", $wholesale_price)/preg_replace("/([^0-9\\.])/i", "", $retail_price)*100);

$price = '<span class="b2bking_both_prices_text b2bking_retail_price_text">'.$retail_text

.'</span><span class="b2bking_both_prices_price b2bking_retail_price_price">'. $retail_price
.' ( '.$margin.'% de marge )'
. '<br></span><span class="b2bking_both_prices_text b2bking_b2b_price_price">'.$wholesale_text
.'</span><span class="b2bking_both_prices_price b2bking_b2b_price_price b2bking_b2b_price_id_'.esc_attr($product_id).'">'
.$wholesale_price.'</span>';


2,762
KingsPlugins replied 4 years ago on May 17, 2022 at 6:48pm

Hi there,

I believe you can do that by adding this to your functions.php:

add_filter('b2bking_filter_wholesale_price_final', function($price, $retail_text, $retail_price, $wholesale_text, $wholesale_price, $product_id){
    $margin=100-round(preg_replace("/([^0-9\\.])/i", "", $wholesale_price)/preg_replace("/([^0-9\\.])/i", "", $retail_price)*100);
    $price = '<span class="b2bking_both_prices_text b2bking_retail_price_text">'.$retail_text.'</span><span class="b2bking_both_prices_price b2bking_retail_price_price">'.$retail_price.' ( '.$margin.'% de marge )'. '<br></span><span class="b2bking_both_prices_text b2bking_b2b_price_price">'.$wholesale_text.'</span><span class="b2bking_both_prices_price b2bking_b2b_price_price b2bking_b2b_price_id_'.esc_attr($product_id).'">'
    .$wholesale_price.'</span>';
    return $price;
}, 10, 6);

Sign In