Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AnanthFlycart/80d38bd9b3d87eefae1e86163cf9341a to your computer and use it in GitHub Desktop.

Select an option

Save AnanthFlycart/80d38bd9b3d87eefae1e86163cf9341a to your computer and use it in GitHub Desktop.
// Calculate Subtotal with Tax (Inclusive Tax)
add_filter('advanced_woo_discount_rules_get_cart_subtotal', function($subtotal) {
if (function_exists('WC')) {
$subtotal = 0;
if(isset(WC()->cart) && WC()->cart != null) {
if (method_exists(WC()->cart, 'get_subtotal')) {
$subtotal = WC()->cart->get_subtotal();
} elseif (isset(WC()->cart->subtotal)) {
$subtotal = WC()->cart->subtotal;
}
$tax_type = get_option('woocommerce_prices_include_tax');
if ($tax_type === 'yes') {
$tax_total = 0;
if (method_exists(WC()->cart, 'get_tax_totals')) {
$tax_total = WC()->cart->get_subtotal_tax();
} elseif (isset(WC()->cart->subtotal_tax)) {
$tax_total = WC()->cart->subtotal_tax;
}
$subtotal = $subtotal + $tax_total;
}
}
}
return $subtotal;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment