Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce price after discount

I am not expert on WooCommerce, i cant find how to display price that calculate on it discount from coupon.

This code, display price after coupon, but also with shipping price - what i dont want, i want to display price after discount, before shipping and tax:

$woocommerce->cart->get_cart_total();

This code display the finnal price without discount and without shipping:

$woocommerce->cart->get_cart_subtotal();

So i tried something like that to get price after discount:

<?php
 $totalp = $woocommerce->cart->get_cart_subtotal();
 $totaldisc = $woocommerce->cart->get_total_discount();
 $resultp = $totalp - $totaldisc; 

 echo ($resultp);
?>

But it show "0" number.

So, i guess there is simple function for what i want (i want to get total cart price after discount, before shipping), but i cant find this function.

like image 268
Oshrib Avatar asked Feb 13 '23 02:02

Oshrib


1 Answers

Answer: i was need to use int's or floats without symbols, and the best way was to check WooCommerce docs here: Woo - Docs , and to search for this variable and use it without () (not function). now it work :)

<?php

$first_number = $woocommerce->cart->subtotal;
$second_number = $woocommerce->cart->discount_total;
$sum_total = $first_number - $second_number;

print ($sum_total);

?>
like image 106
Oshrib Avatar answered Feb 19 '23 04:02

Oshrib