filters – Add second price option based on payment method at cart item price


I need to “show” a second price info for customers on each Woocommerce cart item.

Example: $100 (or $85 via Wire)

This is because we give a storewide 15% discount automatically on checkout, when customers choose a specific payment method.

The actual product price does not need to change, I just need to show the reduced price as a text beside the current item price.

I’m can make the calculation and show it on shop pages, but I can’t do it in the cart item.

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 the same with with the “woocommerce_cart_item_price” hook, I cannot get the cart item’s prices to make the calculations.

How can I make the same calculations for a cart item, within the woocommerce_cart_item_price hook?


Alemao 1 year 2022-11-13T01:15:29-05:00 0 Answers 0 views 0

Leave an answer