Okay
  Public Ticket #3602024
Show total saved per product and totals
Closed

Comments

  •  7
    Jose Perez started the conversation

    Show total saved per product and total

    It is possible to show in the cart, checkout and emails, the total saved per product, take into account that there are products with direct discounts ( sale) and products with tiered discounts, show this data as a meta of the product; also show the total saved totalized by subtotal of the product line and as total of the order.

    Thank you...

  •  1,910
    WebWizards replied

    Hello Jose,

    B2BKing does not directly have any features for showing the amount saved I'm afraid. Therefore to achieve something like this it would be needed to write some custom code snippets to change the displays on the various pages. A bit of PHP knowledge is needed.


    You can use the following function to get the amount saved for a product:

    function get_amount_saved($product_id){
        $product = wc_get_product($product_id);
        $current_price = b2bking()->b2bking_wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ));
        if ($product->is_on_sale()){
            $current_price = b2bking()->b2bking_wc_get_price_to_display( $product, array( 'price' => $product->get_sale_price()));
        }
        $retail_price = b2bking()->get_woocs_price(b2bking()->tofloat(get_post_meta($product_id,'_regular_price', true)));
        $retail_price = b2bking()->b2bking_wc_get_price_to_display( $product, array( 'price' => $retail_price ));
        $difference = $retail_price - $current_price;
        return $difference;
    }
    

    Usage example:

    $amount_saved = get_amount_saved(1234);


    I believe this would give you the amount saved both based on sale price and on tiered price. The function basically compares the user's current price with the regular retail price.


    Some other starting points:

    1. You could work with the code snippet from here to show the total saved in cart as a final line: https://www.businessbloomer.com/woocommerce-display-total-discount-savings-cart/

    2. You could use the following https://www.commercegurus.com/docs/shoptimizer-theme/sale-price-cart/ as a starting point to show the amount saved for each line in cart.


    Kind regards,

    Stefan