WooCommerce: Display Regular & Sale Price @ Cart Table

To display both the regular and sale prices in the cart table for WooCommerce, you can utilize the `woocommerce_cart_item_price` filter. Here’s an example of how you can achieve this:

Step 1: Open your theme’s `functions.php` file.

Step 2: Add the following code to the file:

 

// Function to modify cart item price display
function modify_cart_item_price($product_price, $cart_item, $cart_item_key) {
    $product = $cart_item['data'];
    
    if ($product->is_on_sale()) {
        $regular_price = wc_price($product->get_regular_price());
        $sale_price = wc_price($product->get_price());
        
        $product_price = '<del>' . $regular_price . '</del> <ins>' . $sale_price . '</ins>';
    }
    
    return $product_price;
}
add_filter('woocommerce_cart_item_price', 'modify_cart_item_price', 10, 3);

 

Step 3: Save the file and upload it to your theme directory.

With these steps, the `modify_cart_item_price()` function will be triggered for each item in the cart. It checks if the product is on sale using the `is_on_sale()` method. If it is, it retrieves the regular and sale prices using the `get_regular_price()` and `get_price()` methods respectively. Then, it modifies the product price display to include both prices with appropriate del and ins tags for strikethrough and underline effect.

Now, when you view the cart table, the regular price will be displayed with a strikethrough, and the sale price will be displayed with an underline. This allows customers to see the discounted price clearly.

Please note that this code assumes you’re using the default WooCommerce cart table template. If you have a custom cart template, you may need to adjust the code accordingly to fit your specific implementation.

Categories

Related Blogs

Sort A ACF Repeater Field Results

Filters the field $value after being loaded. Sort a repeater field using a function called array_multisort(). Sorting Filtering Modifying ACF results .

How To add custom product data tabs in WooCommerce

To add custom product data tabs in WooCommerce, you can use the woocommerce_product_data_tabs and woocommerce_product_data_panels hooks. These hooks allow you to add new tabs to the product edit page in the WooCommerce admin area. Here’s a step-by-step guide on how to achieve this:

Top Quick View Plugins WooCommerce

There are several popular WooCommerce quick view plugins that provide a convenient way for customers to view product details without leaving the current page. Keep in mind that the popularity of plugins can change over time, so it’s a good idea to check for the latest information and reviews before making a decision.

Request A Quote