Woocommerce Cart Conditional Subtotal
-
I am working with a logical php function that is meant to compare the woocommerce cart subtotal with a conditional cart subtotal, which excludes products from one category, and reports the difference between the two. This is the code that I currently have to accomplish that:
function new_was_match_condition_subtotal( $match, $operator, $value ) { if ( ! isset( WC()->cart ) ) return; $subtotal = 0; foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $product = $cart_item['data']; $quantity = $cart_item['quantity']; if ( !has_term('donations', 'product_cat', $product->id) ) { $products_subtotal = $product->get_price() * $quantity; $subtotal = $subtotal + $products_subtotal; } } if ( '==' == $operator ) : $match = ( $subtotal == $value ); elseif ( '!=' == $operator ) : $match = ( $subtotal != $value ); elseif ( '>=' == $operator ) : $match = ( $subtotal >= $value ); elseif ( '<=' == $operator ) : $match = ( $subtotal <= $value ); endif; return $match; }This use to work perfectly for me. Unfortunately, since the last update (I was actually several versions old, so I’m not sure which version caused it to stop working), this function is no longer working. I expect that the problem is in the line which excludes the “donations” category from the conditional subtotal:
if ( !has_term('donations', 'product_cat', $product->id) ) {But nothing I have tried for fixing this line has worked at all. Can anyone help me?
The topic ‘Woocommerce Cart Conditional Subtotal’ is closed to new replies.