I'm using woocommerce and "Print Invoices & Packing lists" available at "https://woocommerce.com/products/print-invoices-packing-lists/" . For Display the Total Saving in the woocommerce cart & checkout pages I'm used this code and works perfectly :
function bbloomer_wc_discount_total() {
global $woocommerce;
$cart_subtotal = $woocommerce->cart->cart_contents;
$discount_total = 0;
foreach ($woocommerce->cart->cart_contents as $product_data) {
if ($product_data['variation_id'] > 0) {
$product = wc_get_product( $product_data['variation_id'] );
} else {
$product = wc_get_product( $product_data['product_id'] );
}
if ( !empty($product->sale_price) ) {
$discount = ($product->regular_price - $product->sale_price) * $product_data['quantity'];
$discount_total += $discount;
}
}
if ( $discount_total > 0 ) {
echo '<tr class="cart-discount">
<th>'. __( 'Total Saving :', 'woocommerce' ) .'</th>
<td data-title=" '. __( 'Total Saving :', 'woocommerce' ) .' ">'
. wc_price($discount_total+$woocommerce->cart->discount_cart) .'</td>
</tr>';
}
}
add_action( 'woocommerce_cart_totals_after_order_total', 'bbloomer_wc_discount_total');
add_action( 'woocommerce_review_order_after_order_total', 'bbloomer_wc_discount_total');
This function based in the woocommerce cart contents . How I can Display The Total Saving in the Html Invoice generated By Print Invoices & Packing lists Plugin ( based On the Order Instead of the cart contents ) in the plugin Hooks like :
add_action( 'wc_pip_after_header', 'bbloomer_wc_discount_total'); add_action( 'wc_pip_document_header', 'bbloomer_wc_discount_total');