Sunday, November 13, 2022
HomeWordPress Developmentfilters - Add second worth choice based mostly on fee methodology at...

filters – Add second worth choice based mostly on fee methodology at cart merchandise worth


I have to “present” a second worth information for patrons on every Woocommerce cart merchandise.

Instance: $100 (or $85 by way of Wire)

It’s because we give a storewide 15% low cost robotically on checkout, when prospects select a particular fee methodology.

The precise product worth doesn’t want to alter, I simply want to point out the lowered worth as a textual content beside the present merchandise worth.

I am could make the calculation and present it on store pages, however I am unable to do it within the cart merchandise.

That is the operate I exploit, which works nicely on store pages:

add_filter('woocommerce_get_price_html', operate ($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">by way of Wire</span>';
        } else{
            $vista="<span class="txt-preco-pix"></span><br>" . wc_price($product->get_regular_price() * 0.85) . ' <span class="txt-preco-pix">by way of Wire</span>';
        }
        return $priceHtml . $vista; 
}, PHP_INT_MAX, 3);

However when I attempt to do the identical with with the “woocommerce_cart_item_price” hook, I can’t get the cart merchandise’s costs to make the calculations.

How can I make the identical calculations for a cart merchandise, inside the woocommerce_cart_item_price hook?

Thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments