Coupon fix

This commit is contained in:
Mike Jolley 2011-11-20 00:55:23 +00:00
parent a04551bd35
commit adb6c5f73d
2 changed files with 34 additions and 39 deletions

View File

@ -70,7 +70,6 @@ function woocommerce_process_shop_coupon_meta( $post_id, $post ) {
$woocommerce_errors = array();
if (!$_POST['coupon_amount']) $woocommerce_errors[] = __('Coupon amount is required', 'woothemes');
if ($_POST['discount_type']=='fixed_product' && !$_POST['product_ids']) $woocommerce_errors[] = __('Product discount coupons require you to set "Product IDs" to work.', 'woothemes');
// Add/Replace data to array
$type = strip_tags(stripslashes( $_POST['discount_type'] ));

View File

@ -424,7 +424,7 @@ class woocommerce_cart {
/**
* Function to apply product discounts after tax
*/
function apply_discount_products_after_tax( $total_item_price ) {
function apply_product_discounts_after_tax( $values, $price ) {
if ($this->applied_coupons) foreach ($this->applied_coupons as $code) :
$coupon = &new woocommerce_coupon( $code );
@ -433,8 +433,6 @@ class woocommerce_cart {
if ( !$coupon->apply_before_tax() && $coupon->is_valid() ) :
if (sizeof($this->cart_contents)>0) foreach ($this->cart_contents as $cart_item_key => $values) :
$this_item_is_discounted = false;
// Specific product ID's get the discount
@ -468,12 +466,10 @@ class woocommerce_cart {
if ($coupon->type=='fixed_product') :
$this->discount_total = $this->discount_total + ( $coupon->amount * $values['quantity'] );
elseif ($coupon->type=='percent_product') :
$this->discount_total = $this->discount_total + ( $total_item_price / 100 ) * $coupon->amount;
$this->discount_total = $this->discount_total + ( $price / 100 ) * $coupon->amount;
endif;
endif;
endforeach;
endif;
endforeach;
}
@ -552,7 +548,7 @@ class woocommerce_cart {
$total_item_price = ($discounted_price*$values['quantity']) + $discounted_tax_amount;
// Add any product discounts (after tax)
$this->apply_discount_products_after_tax( $total_item_price );
$this->apply_product_discounts_after_tax( $values, $total_item_price );
// Sub total is based on base prices (without discounts)
$this->subtotal = $this->subtotal + ($base_price*$values['quantity']) + $tax_amount;