php – How to add the item price in the review order section of the checkout page

Question

I have this code that adds an items “each” price in the review order section of the checkout page, which is what i want.

However, it also adds it to the cart page, which i do not want.

How can i update this code to make sure the individual price does not show on the cart page?

<?php

add_filter( ‘woocommerce_cart_item_name’, ‘showing_price_in_cart_items’, 99, 3 );
function showing_price_in_cart_items( $item_name, $cart_item, $cart_item_key ) {
// The WC_Product object
$product = $cart_item[‘data’];

if (empty($product)) {
    return $item_name;
}

// Get the  price
$price = $product->get_price();

// When price doesn't exist
if (empty($price)) {
    return $item_name;
}

// display the price
$item_name .= '<br><small class="product-price">' . __( "£$price each: ", "woocommerce") . $price . '</small>';

return $item_name;

}

0
Raj Sidhu 5 months 2021-05-24T10:54:37-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse