• Hello!

    I have a custom coded cart in my template to create a sidebar cart. I works fine if you add a regular price o sale price in the cart, but if you add a product with a discount from the plugin, it doesn’t show the sale price.

    It only happens if you are not in the cart or checkout page. In those two pages, it works fine.

    This is my code:

    <?php
    foreach($items as $item => $values) {  
        $product = $values['data'];
        
        // Get the product price and sale price (if it has sale price)
        $regular_price = $product->get_regular_price();
        $sale_price = $product->get_sale_price();
        $price = $product->get_price(); // Actual price (can be sale or not)
        if (current_user_can('manage_options')) {
            echo $regular_price.'<br />'; // prints ok regular price
            echo $sale_price.'<br />'; // doesn't print sale price
            echo $price; // prints sale price only if your're on cart o checkout page
        }
        
        // Price formats
        $formatted_regular_price = wc_price($regular_price);
        $formatted_sale_price = wc_price($sale_price);
        $formatted_price = wc_price($price);
        
        // The price
        if ($sale_price && $sale_price < $regular_price) {
            // If it has sale price:
            echo '<p><del>' . $formatted_regular_price . '</del> ' . $formatted_sale_price . '</p>';
        } else {
            // regular price
            echo '<p>' . $formatted_price . '</p>';
        }
    }

    Any help? Thank you!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.