Updated everything so it actually works rather than fails hard

I messed up badly on the original with inheritance of variables, and
after a lot of issues realised that strict matching was necessary due
to the '0' string in woocommerce_get_products_on_sale()

Not hard to tell I am new to php.

Regardless this now functions as intended, stopping discount from being
applied to products with active sale prices or carts with items on sale
inside them.
This commit is contained in:
Alex Bishop 2013-01-29 22:55:03 +10:30
parent 0818bb055e
commit 2379a3a1bb
3 changed files with 16 additions and 9 deletions

View File

@ -954,6 +954,7 @@ class WC_Cart {
$this_item_is_discounted = false;
$product_cats = wp_get_post_terms( $values['product_id'], 'product_cat', array("fields" => "ids") );
$product_ids_on_sale = woocommerce_get_product_ids_on_sale();
// Specific products get the discount
if ( sizeof( $coupon->product_ids ) > 0 ) {
@ -985,9 +986,8 @@ class WC_Cart {
$this_item_is_discounted = false;
// Sale Items excluded from discount
if ( $coupon->exclude_sale_items() && sizeof( woocommerce_get_product_ids_on_sale() ) > 0 )
$product_ids_on_sale = woocommerce_get_product_ids_on_sale();
if ( in_array( $values['product_id'], $product_ids_on_sale ) || in_array( $values['variation_id'], $product_ids_on_sale ) || in_array( $values['data']->get_parent(), $product_ids_on_sale ) )
if ( $coupon->exclude_sale_items == 'yes' )
if ( in_array( $values['product_id'], $product_ids_on_sale, true ) || in_array( $values['variation_id'], $product_ids_on_sale, true ) || in_array( $values['data']->get_parent(), $product_ids_on_sale, true ) )
$this_item_is_discounted = false;
// Apply filter
@ -1106,7 +1106,7 @@ class WC_Cart {
* @param mixed $price
*/
public function apply_product_discounts_after_tax( $values, $price ) {
if ( ! empty( $this->applied_coupons) ) {
foreach ( $this->applied_coupons as $code ) {
$coupon = new WC_Coupon( $code );
@ -1120,6 +1120,7 @@ class WC_Cart {
if ( ! $coupon->apply_before_tax() ) {
$product_cats = wp_get_post_terms( $values['product_id'], 'product_cat', array("fields" => "ids") );
$product_ids_on_sale = woocommerce_get_product_ids_on_sale();
$this_item_is_discounted = false;
@ -1153,9 +1154,8 @@ class WC_Cart {
$this_item_is_discounted = false;
// Sale Items excluded from discount
if ( $coupon->exclude_sale_items() && sizeof( woocommerce_get_product_ids_on_sale() ) > 0 )
$product_ids_on_sale = woocommerce_get_product_ids_on_sale();
if ( in_array( $values['product_id'], $product_ids_on_sale ) || in_array( $values['variation_id'], $product_ids_on_sale ) || in_array( $values['data']->get_parent(), $product_ids_on_sale ) )
if ( $coupon->exclude_sale_items == 'yes' )
if ( in_array( $values['product_id'], $product_ids_on_sale, true ) || in_array( $values['variation_id'], $product_ids_on_sale, true ) || in_array( $values['data']->get_parent(), $product_ids_on_sale, true ) )
$this_item_is_discounted = false;
// Apply filter

View File

@ -317,12 +317,12 @@ class WC_Coupon {
}
// Exclude Sale Items
if ( exclude_sale_items() && sizeof( $woocommerce_get_product_ids_on_sale) > 0 ) {
if ( $this->exclude_sale_items == 'yes' ) {
$valid_for_cart = true;
$product_ids_on_sale = woocommerce_get_product_ids_on_sale();
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( in_array( $cart_item['product_id'], $product_ids_on_sale ) || in_array( $cart_item['variation_id'], $product_ids_on_sale ) || in_array( $cart_item['data']->get_parent(), $product_ids_on_sale ) ) {
if ( in_array( $cart_item['product_id'], $product_ids_on_sale, true ) || in_array( $cart_item['variation_id'], $product_ids_on_sale, true ) || in_array( $cart_item['data']->get_parent(), $product_ids_on_sale, true ) ) {
$valid_for_cart = false;
}
}

View File

@ -192,4 +192,11 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
<?php do_action( 'woocommerce_after_cart_totals' ); ?>
<div class="debug">
<?php
print_r(woocommerce_get_product_ids_on_sale() );
print_r( $woocommerce )
?>
</div>
</div>