Bruttosumme minus (Bruttosumme geteilt durch 1,16)
So rechnet WordPress nicht - oder Online-Shops per se nicht.
Am Anfang der Berechnung wird alles auf NULL gesetzt:
protected $data = array(
'parent_id' => 0,
'status' => '',
'currency' => '',
'version' => '',
'prices_include_tax' => false,
'date_created' => null,
'date_modified' => null,
'discount_total' => 0,
'discount_tax' => 0,
'shipping_total' => 0,
'shipping_tax' => 0,
'cart_tax' => 0,
'total' => 0,
'total_tax' => 0,
);
Alles anzeigen
WordPress und eigentlich _jeder Warenkorb in einem eCommerce Projekt kennt:
'discount_tax' => 0,
'shipping_tax' => 0,
'cart_tax' => 0,
'total_tax' => 0,
Der Shop rechnet immer PLUS nie MINUS Steuer.
$this->set_total_tax( (float) $this->get_cart_tax() + (float) $this->get_shipping_tax() );
$this->set_total( NumberUtil::round( $cart_total + $fees_total + $this->get_shipping_total() + $this->get_cart_tax() + $this->get_shipping_tax(), wc_get_price_decimals() ) );
Hier bildet der Shop die Summen
$fees_total = 0;
$shipping_total = 0;
$cart_subtotal_tax = 0;
$cart_total_tax = 0;
$cart_subtotal = $this->get_cart_subtotal_for_order();
$cart_total = $this->get_cart_total_for_order();
// Sum shipping costs.
foreach ( $this->get_shipping_methods() as $shipping ) {
$shipping_total += NumberUtil::round( $shipping->get_total(), wc_get_price_decimals() );
}
$this->set_shipping_total( $shipping_total );
// Sum fee costs.
foreach ( $this->get_fees() as $item ) {
$fee_total = $item->get_total();
if ( 0 > $fee_total ) {
$max_discount = NumberUtil::round( $cart_total + $fees_total + $shipping_total, wc_get_price_decimals() ) * -1;
if ( $fee_total < $max_discount && 0 > $max_discount ) {
$item->set_total( $max_discount );
}
}
$fees_total += $item->get_total();
}
// Calculate taxes for items, shipping, discounts. Note; this also triggers save().
if ( $and_taxes ) {
$this->calculate_taxes();
}
// Sum taxes again so we can work out how much tax was discounted. This uses original values, not those possibly rounded to 2dp.
foreach ( $this->get_items() as $item ) {
$taxes = $item->get_taxes();
foreach ( $taxes['total'] as $tax_rate_id => $tax ) {
$cart_total_tax += (float) $tax;
}
foreach ( $taxes['subtotal'] as $tax_rate_id => $tax ) {
$cart_subtotal_tax += (float) $tax;
}
}
$this->set_discount_total( NumberUtil::round( $cart_subtotal - $cart_total, wc_get_price_decimals() ) );
$this->set_discount_tax( wc_round_tax_total( $cart_subtotal_tax - $cart_total_tax ) );
$this->set_total( NumberUtil::round( $cart_total + $fees_total + $this->get_shipping_total() + $this->get_cart_tax() + $this->get_shipping_tax(), wc_get_price_decimals() ) );
Alles anzeigen
Das schöne bei Open Source ist, man kann wirklich nachsehen, wie ein Shop etwas macht.
Und ja - WooCommerce kann auf Zwischensummen runden - was zu abenteuerlichen und im EU Binnenmarkt zu falschen Ergebnissen führt. Die Rundung auf die Zwischensumme ist trotzdem mathematisch richtig.