Sign in to unlock all code snippets and resources
100% tested and verified code snippets
New here? Register for free to get started
© Copyright – 2024 – All Rights Reserved. Created by SuperWP
By default, the WooCommerce cart page displays the total price of all the items in the cart, but it doesn’t show the regular price of each item. This can be a problem for online store owners who offer discounts or have special pricing for their products. However, with a simple customization, you can easily display the regular price of each item on your WooCommerce cart page. In this post, we’ll show you how to do it step by step, so you can give your customers a better shopping experience and increase your sales in your WooCommerce store
The add_filter() function registers the woo_show_regular_price_on_cart function to be called whenever the woocommerce_cart_item_price filter is applied.
The woo_show_regular_price_on_cart function takes three parameters: $price, $values, and $cart_item_key.
The $price parameter is the current price of the product in the cart.
The $values parameter contains the cart item data including the product ID, quantity, and other details.
The $cart_item_key parameter is the unique identifier for the cart item.
The function checks if the product is on sale by calling the is_on_sale() method on the product object.
If the product is on sale, the function retrieves the regular price of the product using the get_regular_price() method and formats it using the wc_price() function.
The function then adds the formatted regular price to the cart item’s price using HTML and CSS to strike through the regular price and reduce its opacity.
Finally, the function returns the updated price with the regular price included.
Features Added:
How to show regular price in cart page.
Stay UpTo Date with Latest Post And news: