Показывать промежуточную итоговую сумму по элементу корзины, когда купон применяется в Woocommerce - PullRequest
0 голосов
/ 29 января 2019

Моя цель выглядит следующим образом: enter image description here

Я попробовал этот код, чтобы добиться этого:

add_filter( 'woocommerce_cart_item_subtotal', 'show_coupon_item_subtotal_discount', 100, 3 );
function show_coupon_item_subtotal_discount( $subtotal, $cart_item, $cart_item_key ){
    if( $cart_item['line_subtotal'] !== $cart_item['line_total'] ) {
        $subtotal = sprintf( '<del>%s</del> <ins>%s<ins>',  wc_price($cart_item['line_subtotal']), wc_price($cart_item['line_total']) );
    }
    return $subtotal;
}

Но, к сожалению, неверная ценаВы можете увидеть здесь.Что не так с этим кодом?

enter image description here

Это касается этой страницы: keimster.de/kasse

1 Ответ

0 голосов
/ 29 января 2019

Обновление 2 - Обработка налогов на общую сумму товара со скидкой.

Попробуйте следующее, чтобы при применении купона отображалась правильная цена промежуточного итога:

add_filter( 'woocommerce_cart_item_subtotal', 'show_coupon_item_subtotal_discount', 100, 3 );
function show_coupon_item_subtotal_discount( $subtotal, $cart_item, $cart_item_key ){
    $line_subtotal = $cart_item['line_subtotal'];
    $line_total    = $cart_item['line_total'];
    if( $line_subtotal !== $line_total ) {
        $subtotal_tax  = $cart_item['line_subtotal_tax'];
        $total_tax     = $cart_item['line_tax'];
        $incl_taxes    = WC()->cart->display_prices_including_tax() && $cart_item['data']->is_taxable();

        $raw_subtotal = $incl_taxes ? $line_subtotal + $subtotal_tax : $line_subtotal;
        $raw_total    = $incl_taxes ? $line_total + $total_tax : $line_total;
        $subtotal     = sprintf( '<del>%s</del> <ins>%s<ins>',  wc_price($raw_subtotal), wc_price($raw_total) );
    }
    return $subtotal;
}

Код помещается в файл function.php вашей активной дочерней темы (или активной темы).Проверено и работает.

...