awesomemotive / easy-digital-downloads

Sell digital downloads through WordPress
https://easydigitaldownloads.com
GNU General Public License v2.0
865 stars 475 forks source link

Per product tax rates #1511

Closed pippinsplugins closed 10 years ago

pippinsplugins commented 11 years ago

Most ecommerce plugins have this and we need to add it to.

Per product tax rates that let site admins define a tax rate for individual products.

For example, Product A gets taxed at 7% and Product B gets taxed at store default, such as 15%.

xaliander commented 11 years ago

I addded $item_id to both of these functions - maybe this helps you. (I then removed warnings saying call of function missing argument by adding it...)

function edd_get_tax_rate( $country = false, $state = false, $item_id ) {
[...]
if($item_id == 8)    // If example product ID is 8 override tax rate.
     $rate = 0.19;
}
function edd_calculate_tax( $amount, $sum = true, $country = false, $state = false, $item_id ) {
[...]
    echo "<$rate>";  // shows what rate has been applied.
}
pippinsplugins commented 11 years ago

That's on the right track but it is actually more in depth than that.

Currently, the tax amount paid on a cart is calculated globally. We need to change it so that it is calculated on a per-product basis always and then just add each tax amount together.

We do already calculate the tax for each product, but the function that determines how much tax needs to be charged for the entire order doesn't take those calculations into account.

pippinsplugins commented 11 years ago

The cart total is calculated here: https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/includes/cart/functions.php#L482

The $tax in that function needs to be adjusted for per-product taxes.

xaliander commented 11 years ago

By the way I found another little bug... I think,... quick fix:

if ( ! edd_prices_show_tax_on_checkout() && edd_prices_include_tax() ) { in my opinion should be more like this: if ( edd_prices_show_tax_on_checkout() && edd_prices_include_tax() ) {

So the complete function is like:

function edd_cart_item_price( $item_id = 0, $options = array() ) { global $edd_options;

$price = edd_get_cart_item_price( $item_id, $options );
$label = '';

if ( edd_is_cart_taxed() ) {

    if ( edd_prices_show_tax_on_checkout() && edd_prices_include_tax() ) {
        $label .= ' ' . __( '(ex. tax)', 'edd' );
    }

    if ( edd_prices_show_tax_on_checkout() && ! edd_prices_include_tax() ) {
        $label .= ' ' . __( '(incl. tax)', 'edd' );
    }

}

$price = edd_currency_filter( edd_format_amount( $price ) );

return esc_html( $price . $label );

}

pippinsplugins commented 11 years ago

What's the bug? I see the proposed fix, but not what the problem is :)

xaliander commented 11 years ago

The prices on the checkout page table were shown without taxes, but the (excl. tax) was missing. BTW: I'm afraid I'll have to ask for a refund now. There are just to many bugs in the German version and I have run out of time for my purposes EDD thereby unfortunately is completely worthless. I will contact you via E-Mail.

pippinsplugins commented 11 years ago

Note, please keep all account issues (refunds, etc) off of github. Github is only for dev.

I'd love to get the German issues worked out but I literally cannot replicate them at all. We have several VERY active German users and NONE of them have these problems.

pippinsplugins commented 11 years ago

This is going to involve a complete rewrite of the tax system. The way the taxes are calculated and made available to payment gateways is really dumb and too hard and unreliable to work with.

pippinsplugins commented 10 years ago

I can't think of any way to do this without also added per-product / per-country/state tax rates. That is way too complex for individual products.

I'm going to, instead, allow products to be marked as exclusive of tax.