Okay
  Public Ticket #3045451
Margin calculator
Closed

Comments

  •  1
    Anthony started the conversation

    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,214
    WebWizards replied

    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://woocommerce-b2b-plugin.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://woocommerce-b2b-plugin.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

  •  1
    Anthony replied

    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,214
    WebWizards replied

    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);
    
  •  1
    Anthony replied

    Thank you ! It work well !