Filter – Add a second price option based on payment method on the price of the cart item

I need to “show” second price information to customers on each Woocommerce cart item.

Example: $100 (or $85 via wire)

This is because when customers choose a specific payment method, we automatically offer a 15% discount at checkout.

There is no need to change the actual product price, I just need to show the lower price as text next to the current item price.

I can calculate and show it on shop pages, but I can’t do it in cart items.

This is the function I use, which works well on shop pages:

add_filter('woocommerce_get_price_html', function ($priceHtml, $product) {
        if ( $product->is_on_sale() ){
            $vista="<span class="txt-preco-pix"></span><br>" . wc_price($product->get_sale_price() * 0.85) . ' <span class="txt-preco-pix">via Wire</span>';
        } else{
            $vista="<span class="txt-preco-pix"></span><br>" . wc_price($product->get_regular_price() * 0.85) . ' <span class="txt-preco-pix">via Wire</span>';
        }
        return $priceHtml . $vista; 
}, PHP_INT_MAX, 3);

But when I try to do this with “woocommerce_cart_item_price” hook, I can’t get cart item prices to calculate.

How can I do the same calculation for cart items within the woocommerce_cart_item_price hook?

Thank you

Leave a Comment