• Resolved broder

    (@broder)


    Hi,

    So I calculate the total savings of the order / cart like this (example for order):

    
    foreach( $order->get_items() as $item_id => $item ) {
    $quantity = $item->get_quantity();
    if ( $product instanceof WC_Product ) {
    $regular_price = $product->get_regular_price();
    $sale_price = $product->get_sale_price();
    if($product->is_on_sale()) {
    $savings += ($regular_price - $sale_price) * $quantity;
    }
    }
    }
    
    echo $savings;
    

    Is it possible to get this to display in the pdf as well? I have looked at it but not sure if I can get the order / product object inside of the template. Before I lose my mind trying to get it to work.

    Thanks in advance!

    • This topic was modified 2 years, 4 months ago by broder.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @broder,

    You don’t need that code to get the discount price between the regular price and the sale price, we already have a plugin that does so: Sale price as order discount for WooCommerce

    However, please note that your old orders won’t be affected, only the new orders will calculate the discount automatically, from the difference between the product regular and sale prices.

    Thread Starter broder

    (@broder)

    Wow, and exactly in the format I wanted without changing anything. Thank you.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m glad to hear that this is what you wanted!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom discount calculation in template’ is closed to new replies.