diff --git a/classes/checkout.class.php b/classes/checkout.class.php index 3a2b32e2621..4d078271c62 100644 --- a/classes/checkout.class.php +++ b/classes/checkout.class.php @@ -688,7 +688,8 @@ class woocommerce_checkout { // Calculate discounted price ex. vat if (get_option('woocommerce_prices_include_tax')=='yes') : - $cost = $woocommerce->cart->get_discounted_price( $values, $_product->get_price() ) / (($rate/100) + 1); + $base_rate = $_tax->get_shop_base_rate( $this->tax_class ); + $cost = $woocommerce->cart->get_discounted_price( $values, $_product->get_price() ) / (($base_rate/100) + 1); else : $cost = $woocommerce->cart->get_discounted_price( $values, $_product->get_price() ); endif; diff --git a/classes/gateways/gateway-paypal.php b/classes/gateways/gateway-paypal.php index 313f63e2a70..ef9c8ee1536 100644 --- a/classes/gateways/gateway-paypal.php +++ b/classes/gateways/gateway-paypal.php @@ -221,52 +221,56 @@ class woocommerce_paypal extends woocommerce_payment_gateway { endif; if (get_option('woocommerce_prices_include_tax')=='yes') : - // Don't pass - paypal borks tax due to prices including tax. PayPal has no option for tax inclusive pricing. - else : + + // Tax $paypal_args['tax_cart'] = $order->get_total_tax(); - endif; - - // Cart Contents - $item_loop = 0; - if (sizeof($order->items)>0) : foreach ($order->items as $item) : - if ($item['qty']) : - - $item_loop++; - - $item_name = $item['name']; - - $item_meta = &new order_item_meta( $item['item_meta'] ); - if ($meta = $item_meta->display( true, true )) : - $item_name .= ' ('.$meta.')'; - endif; - - if (get_option('woocommerce_prices_include_tax')=='yes') : + + // Don't pass items - paypal borks tax due to prices including tax. PayPal has no option for tax inclusive pricing sadly. Pass 1 item for the order items overall + $paypal_args['item_name_1'] = sprintf(__('Order #%s' , 'woothemes'), $order->id); + $paypal_args['quantity_1'] = 1; + $paypal_args['amount_1'] = number_format($order->order_total - $order->order_shipping - $order->get_total_tax(), 2, '.', ''); + + // Shipping Cost + if ($order->order_shipping>0) : + $paypal_args['item_name_2'] = __('Shipping cost', 'woothemes'); + $paypal_args['quantity_2'] = '1'; + $paypal_args['amount_2'] = number_format($order->order_shipping, 2); + endif; - // Since prices include tax we cannot send lines, otherwise we will get rounding errors when paypal re-calcs the totals - // Paypal also incorrectly calculates discounts when prices are tax inclusive because coupons are removed from the tax inclusive price - $paypal_args['item_name_'.$item_loop] = $item['qty'] . ' x ' . $item_name; - $paypal_args['quantity_'.$item_loop] = 1; + else : + + // Tax + $paypal_args['tax_cart'] = $order->get_total_tax(); + + // Cart Contents + $item_loop = 0; + if (sizeof($order->items)>0) : foreach ($order->items as $item) : + if ($item['qty']) : - // Add tax to this cost for paypal for the entire row to prevent rounding issues - $paypal_args['amount_'.$item_loop] = $order->get_row_cost( $item, true ); + $item_loop++; - else : + $item_name = $item['name']; + $item_meta = &new order_item_meta( $item['item_meta'] ); + if ($meta = $item_meta->display( true, true )) : + $item_name .= ' ('.$meta.')'; + endif; + $paypal_args['item_name_'.$item_loop] = $item_name; $paypal_args['quantity_'.$item_loop] = $item['qty']; $paypal_args['amount_'.$item_loop] = number_format($item['cost'], 2, '.', ''); endif; - - endif; - endforeach; endif; + endforeach; endif; + + // Shipping Cost + if ($order->order_shipping>0) : + $item_loop++; + $paypal_args['item_name_'.$item_loop] = __('Shipping cost', 'woothemes'); + $paypal_args['quantity_'.$item_loop] = '1'; + $paypal_args['amount_'.$item_loop] = number_format($order->order_shipping, 2); + endif; - // Shipping Cost - if ($order->order_shipping>0) : - $item_loop++; - $paypal_args['item_name_'.$item_loop] = __('Shipping cost', 'woothemes'); - $paypal_args['quantity_'.$item_loop] = '1'; - $paypal_args['amount_'.$item_loop] = number_format($order->order_shipping, 2); endif; $paypal_args_array = array();