i want when the product has a discount, in the cart, in the subtotal instead of showing the price with the discount, it will show the price without the discount, see the picture below and you will understand :
i use the following hook, when 1 product is in the cart, it displays correctly, but when a product with a price of $20 is added to the cart, instead of the sum of 2 products, the price of the second product, which is $20, is displayed in subtotal to give
function filter_woocommerce_cart_subtotal( $subtotal, $compound, $cart ) {
foreach ( WC()->cart->get_cart() as $key => $cart_item ) {
$subtotal = wc_price( $cart_item['data']->get_regular_price() * $cart_item['quantity'] );
}
return $subtotal;
} add_filter( 'woocommerce_cart_subtotal', 'filter_woocommerce_cart_subtotal', 10, 3 );
thank you for your time and answering my question
2
Answers
it looks like you’re always overwriting your $subtotal instead of adding to it