在Woocommerce中应用优惠券时显示罢工的购物车小计

时间:2019-01-29 07:33:08

标签: php wordpress woocommerce cart subtotal

我的目标如下: 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 :(得分:1)

更新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文件中。经过测试,可以正常工作。

相关问题