的车计算的费用Woocommerce格式显示价格

问题描述 投票:0回答:1

我手动修改车总(10£)的价格时,有在车4项并且没有项目是从类别:圣诞。

这实际上为用户提供了优惠+“免费送货”。但是,总量不匹配,它可以是混乱给用户仍显示为航运收费。

有手动应用虚拟“免费送货应用 - £3.00”的方式来基于这些条件的车?只是为了更清楚用户?

我明白,我目前使用的钩手动修改价格,而不是格式化的价格显示。

enter image description here

add_filter( 'woocommerce_calculated_total', 'calculated_total', 10, 2 );
function calculated_total( $total, $cart ) {
    $taster_count = 4;
    $item_count   = $cart->get_cart_contents_count();
    $chistm_count = 0;

    foreach ( $cart->get_cart() as $cart_item ) {
        if ( ! has_term( 'christmas', 'product_cat', $cart_item['product_id'] ) ) {
            $chistm_count += $cart_item['quantity'];
        }
    }
    if( $taster_count == $item_count && $chistm_count == $taster_count  )

        //HERE TRY TO DISPLAY A DUMMY FREE SHIPPING MESSAGE
        $discount = 3.00;
        $cart->add_fee( 'Taster Box Offer! Free Shipping', -$discount);

        return 10;
    return $total;
}
php wordpress woocommerce shopping-cart hook-woocommerce
1个回答
0
投票

想出如何解决这个问题。我手动添加的$ 3.00 woocommerce_cart_calculate_fee然后减去这一关总充当“负费”,即折扣。

    add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees2', 10, 1 );

function add_recurring_postage_fees2(WC_Cart $cart ) {

  $items_count  = WC()->cart->get_cart_contents_count();

    if ( $items_count == 4 ) {
        $discount = 3.00;
        $cart->add_fee( 'Taster Box Free Shipping', -$discount);
        return;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.