I try to show the subtotal price and sale price in the Cart and Checkout page for each individual product. I already managed to add the sales price (24TL) to the regular price (33TL) with the following code:
/**
* Show sale prices on the Cart and Checkout pages
*/
function my_custom_show_sale_price( $old_display, $cart_item, $cart_item_key ) {
$price_string = $old_display;
$product = $cart_item['data'];
if ( $product ) {
$price_string = $product->get_price_html();
}
return $price_string;
}
add_filter( 'woocommerce_cart_item_price', 'my_custom_show_sale_price', 10, 3 );
add_filter( 'woocommerce_cart_item_subtotal', 'my_custom_show_sale_price', 10, 3 );
Unfortunately the above code shows the product price only for one piece not for the subtotal (in this case it should be 66TL / 48TL) in the cart or checkout page.
After some digging i found the following price filter to show the price per item as subtotal in my default cart.php file - where the price displayed the correct way before i added the sales price to it with the code form above.
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key );
}
}
Any idea how to change the first block of code to show the product price per item as subtotal?