I am working with a 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;
}
Unfortunately, since the last update, 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?
Hey perfectword,
Unfortunately, it would require quite some time and customization of the theme to achieve this, so I am sorry to tell you that this is not covered by our support. However, if it’s really important for you to get this done, you can always hire a freelancer to do the job for you :)
Best regards,
Basilis