• Resolved consultim

    (@timfosse)


    I am currently using this code to display the total amount saved (regular price minus the sale price) and it works fine:

    <?php
    
    function wc_discount_total_30() {
        global $woocommerce;
        $discount_total = 0;
        foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {
            $_product = $values['data'];
            if ( $_product->is_on_sale() ) {
                $regular_price = $_product->get_regular_price();
                $sale_price = $_product->get_sale_price();
                $discount = ($regular_price - $sale_price) * $values['quantity'];
                $discount_total += $discount;
            }
        }
        if ( $discount_total > 0 ) {
            echo '<tr>
            <th class="rabatt_tittel">Total savings</th>
            <td class="rabatt_sum">-'
            . wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'</td>
            </tr>';
        }
    }
    
    add_action( 'woocommerce_review_order_before_order_total', 'wc_discount_total_30' , 50);

    `

    However, if someone uses a coupon for let’s say $10, that $10 is added to the total discount which is technically correct behaviour.

    What I want to achieve is to have that code above display the sale discount only, as the coupon discount is added on a seperate line and I want to have them separated.

    How can I achieve this?

    • This topic was modified 3 years, 9 months ago by consultim.
    • This topic was modified 3 years, 9 months ago by consultim.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    laceyrod

    (@laceyrod)

    Automattic Happiness Engineer

    Hi there,

    This thread has been inactive for a bit, so I’m going to mark it as Resolved now for the overall health of the forums. Please feel free to check out the resources listed above for additional assistance.

    Alternatively, if you need to have this custom-coded, I can recommend the following experts for help: https://woocommerce.com/customizations/

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display product discount in order review’ is closed to new replies.