Skip to content

Instantly share code, notes, and snippets.

@PayteR
Last active June 10, 2019 20:15
Show Gist options
  • Save PayteR/a2d89e3bf41d080397c92cf6e13a80dd to your computer and use it in GitHub Desktop.
Save PayteR/a2d89e3bf41d080397c92cf6e13a80dd to your computer and use it in GitHub Desktop.
Oprava dane pri zlave pre Superfaktura plugin
/**
* Oprava dane pri zlave pre Superfaktura plugin - min. verzia 1.8.21
*
* Opravuje chybu, ked dan zlavy vychadza nespravne, napr.
* ak je cena 9.90 + 2.50 doprava, tak potom 7% zlava spravi
* ze dan pri zlave je nespravne 19% kvoli nespravnemu
* prepoctu na strane Woocommerce
*
* https://github.com/woocommerce/woocommerce/issues/23835
* https://github.com/woocommerce/woocommerce/issues/23827
*/
/**
* @param array $discount_data
* @param \WC_Order $order
* @return mixed
*/
function sf_discount_tax_data_fix($discount_data, $order) {
$discount_price = $order->get_total_discount(false);
$cart_total = $order->get_total();
$cart_tax = $order->get_total_tax();
$cart_total_tax_excluded = $cart_total - $cart_tax;
$discount_tax = round(($cart_total / $cart_total_tax_excluded) * 100) - 100;
$discount_data['unit_price'] = ($discount_price / (1 + $discount_tax / 100)) * -1;
$discount_data['tax'] = $discount_tax;
return $discount_data;
}
add_filter('sf_discount_data', 'sf_discount_tax_data_fix', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment