Display The Subtotal Before Discount In Woocommerce Cart

Display The Subtotal Before Discount In Woocommerce Cart. I created several ‘single product’ coupons on WooCommerce. To keep things simple, these coupons apply to just one product and offer a certain discount.

On the WooCommerce cart and checkout pages, products are still displayed at regular prices, but then the discount is shown at the bottom of the table to correct the final total.

I want to display each product with the correct value, not the exact total at the end.

Are you create woocommerce Display The Subtotal Before Discount In Woocommerce Cart. then go to custom code working. just simply working this code implement child theme and functions.php page and show the discount print and subtotal and discount total print

WooCommerce: Show product price after coupon discount WordPress

WooCommerce conditional subtotal cart discounts

And Woocommerce Display Discount On the cart


Hook into WC()->cart->get_cart_subtotal()?


Woocommerce get cart total price in a number format [closed]

function codemanhouse_discount() {
   global $woocommerce;
   $subTotal = $woocommerce->cart->total;

   $totalamount = (float)$subTotal;

   $codemanhouse_discount = $totalamount * 7/100;

   foreach ( $woocommerce->cart->get_cart() as $cw_cart_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'];
            $codemanhouse_discount += $discount;
   if ( $codemanhouse_discount > 0 ) {
        echo '<tr class="cart-discount">
    <th>'. __( '7% Discount', 'woocommerce' ) .'</th>
    <td data-title=" '. __( 'Discount', 'woocommerce' ) .' ">'
            . wc_price( $codemanhouse_discount + $woocommerce->cart->discount_cart ) .'</td>
    echo '<tr>
    <th>'. __( 'Total Amonunt', 'woocommerce' ) .'</th>
    <td data-title=" '. __( 'Total Amonunt', 'woocommerce' ) .' ">'
            . wc_price( $totalamount - $codemanhouse_discount ) .'</td>
add_action( 'woocommerce_cart_totals_after_order_total', 'codemanhouse_discount');
add_action( 'woocommerce_review_order_after_order_total', 'codemanhouse_discount');

Updating cart subtotal in WooCommerce

PHP Snippet: show slashed original and discounted subtotal @ WooCommerce Cart

You can see it trying this working code for WooCommerce version 2.6.x and 3.0+:

I want to get it as a float number like so: 21.00 but I don’t know how to get it. My code outputs weird results, this is my exact code:

just using this code

if ( ! WC()->cart->prices_include_tax ) {
    $amount = WC()->cart->cart_contents_total;
} else {
    $amount = WC()->cart->cart_contents_total + WC()->cart->tax_total;

or any type code

global $woocommerce;

$subTotal = $woocommerce->cart->total;
$totalamount = (float)$subTotal;

Get coupon data from WooCommerce orders

In your case you have to use get_discount_type() method or is_type( ‘cash_back_fixed’ ) method …

Here is the way to do it:

To get the coupons discount amounts (and to use also coupons types methods) here is the way:

$order = wc_get_order( $order_id );

$order_items = $order->get_items('coupon');

// print_r($order_items); // For testing

foreach( $order_items as $item_id => $item ){

    // Retrieving the coupon ID reference
    $coupon_post_obj = get_page_by_title( $item->get_name(), OBJECT, 'shop_coupon' );
    $coupon_id = $coupon_post_obj->ID;

    // Get an instance of WC_Coupon object (necessary to use WC_Coupon methods)
    $coupon = new WC_Coupon($coupon_id);

    ## Filtering with your coupon custom types
    if( $coupon->is_type( 'cash_back_fixed' ) || $coupon->is_type( 'cash_back_percentage' ) ){

        // Get the Coupon discount amounts in the order
        $order_discount_amount = wc_get_order_item_meta( $item_id, 'discount_amount', true );
        $order_discount_tax_amount = wc_get_order_item_meta( $item_id, 'discount_amount_tax', true );

        ## Or get the coupon amount object
        $coupons_amount = $coupons->get_amount();