Skip to content

Instantly share code, notes, and snippets.

@kosarlukascz
Last active November 29, 2021 12:44
Show Gist options
  • Save kosarlukascz/c287943c4082ba2c8c41e825c0739623 to your computer and use it in GitHub Desktop.
Save kosarlukascz/c287943c4082ba2c8c41e825c0739623 to your computer and use it in GitHub Desktop.
Ušetříte do pokladny
add_action('woocommerce_cart_totals_before_order_total', 'wc_discount_total', 99);
add_action('woocommerce_review_order_before_order_total', 'wc_discount_total', 99);
function wc_discount_total()
{
global $woocommerce;
$discount_total = 0;
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
if ($_product->is_on_sale()) {
$regular_price = $_product->get_regular_price();
$sale_price = $_product->get_sale_price();
$discount = ($regular_price - $sale_price) * $values['quantity'];
$discount_total += $discount;
}
}
if ($discount_total > 0) {
echo '<tr class="cart-discount">
<th>' . __('Nákupem ušetříte', 'woocommerce') . '</th>
<td data-title=" ' . __('You Saved', 'woocommerce') . ' ">'
. wc_price($discount_total + $woocommerce->cart->discount_cart) . '</td>
</tr>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment