【问题标题】:Woocommerce format price display of cart calculated fees购物车计算费用的 Woocommerce 格式价格显示
【发布时间】:2018-11-28 22:15:48
【问题描述】:

当购物车中有 4 件商品并且没有任何商品属于以下类别时,我正在手动修改购物车的总价格(至 10 英镑):圣诞节.

这实质上为用户提供了折扣 + “免费送货”。但是,总数不匹配,并且可能会使用户感到困惑,因为运费仍显示为已收费。

有没有办法根据这些条件手动将虚拟“已应用免费送货 - £3.00” 应用到购物车?只是为了让用户更清楚?

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

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】:

    想出了如何解决这个问题。我手动添加了 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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-01
      • 1970-01-01
      • 2020-03-11
      • 2023-01-15
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 2019-12-30
      • 2019-04-19
      相关资源
      最近更新 更多