Woocommerce格式的价格显示购物车计算的费用 [英] Woocommerce format price display of cart calculated fees

查看:143
本文介绍了Woocommerce格式的价格显示购物车计算的费用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当购物车中有 4个商品且其中一个商品都不属于以下类别时,我正在手动修改购物车总计的价格(至10英镑):圣诞节.

I am manually modifying the price of the cart total (to £10) when there are 4 items in the cart and none of the items are from the category: christmas.

这实际上为用户提供了折扣+ 免费送货" .但是,总计不匹配,由于运费仍显示为已收费,因此可能会使用户感到困惑.

This essentially gives the user a discount + "Free Shipping". However, the total does not match up and it can be confusing to the user as shipping is still shown as charged.

是否有一种方法可以根据这些条件将虚拟的已应用免费送货-3.00英镑" 应用于购物车?只是为了让用户更清楚?

Is there a way to manually apply a dummy "Free Shipping Applied -£3.00" to the cart based on these conditions? Just to make it clearer for the user?

我了解我当前使用的挂钩是手动修改价格,而不是格式化价格显示.

I understand that the hook I am using currently is to modify the price manually, but not for formatted price display.

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;
}

推荐答案

找出解决方法.我手动添加了woocommerce_cart_calculate_fee 3.00美元,然后从总数中减去了这笔费用,以此作为负费用",即打折.

Figured out how to solve this. I manually added a woocommerce_cart_calculate_fee of $3.00 then to minus this off the total to act as a "negative fee" i.e. A discount.

    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;
    }
}

这篇关于Woocommerce格式的价格显示购物车计算的费用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆