I need to change my WooCommerce mini cart. I've searched a lot but can't find the right filter for this.
This is my current situation:
Now I want to change the price to get this:
So I need filter which can change the price there. I need to check if the product is on sale and if this is true I want to add the old price in front of the new price.
you can use woocommerce_cart_item_price
hook to get the get_price_html
instead of the price but this hook will modify the price in the mini cart and in the cart page.
add_filter( 'woocommerce_cart_item_price', 'change_item_price', 10, 3 );
function change_item_price( $price, $cart_item, $cart_item_key ) {
$price = $cart_item['data']->get_price_html();
return $price;
}
if you want to change the price only in the mini cart you can add condition as follow:
add_filter( 'woocommerce_cart_item_price', 'change_item_price', 10, 3 );
function change_item_price( $price, $cart_item, $cart_item_key ) {
if ( ! is_cart() ) {
$price = $cart_item['data']->get_price_html();
}
return $price;
}