I am using a function to apply a custom price to products within a certain category based on user role. Here is a shortened example:
function return_custom_discounted_price($price, $product) {
$current_user = wp_get_current_user();
$newPrice = $price;
$prodID = $product->get_id();
if( in_array('example_customer', $current_user->roles) && !is_admin()){
if(has_term( 'example-category', 'product_cat', $prodID )){
$newPrice = $price * .9;
}
}
return $newPrice;
}
add_filter('woocommerce_product_get_price', 'return_custom_discounted_price', 10, 2);
However, if a product in this category is added from a grouped product, the discount is applied twice in the cart. For example if the product was $100, the cart applies:
(100 * .9) * .9 = 81
when it should just be
100 * .9 = 90
Which is strange because the code works fine if you add the same product by itself and NOT from the grouped product.
I am also using the Product Addons WooCommerce extension on these grouped products. I use jQuery to show/hide child products of the grouped product base off of their add-on selection. The add-on is not applying any cost change.
Why is this happening in the cart?