购物车计算费用的 Woocommerce 格式价格显示
Woocommerce format price display of cart calculated fees
当购物车中有 4 件商品时,我正在手动修改购物车总价(至 £10),其中 none 件商品来自类别:圣诞节.
这实质上是给用户一个折扣+"Free Shipping"。但是,总数不匹配,这可能会让用户感到困惑,因为运费仍显示为已收费。
有没有办法根据这些条件手动将虚拟 "Free Shipping Applied -£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;
}
想出如何解决这个问题。我手动添加了 3.00 美元的 woocommerce_cart_calculate_fee
,然后从总额中减去这个作为 "negative 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;
}
}
当购物车中有 4 件商品时,我正在手动修改购物车总价(至 £10),其中 none 件商品来自类别:圣诞节.
这实质上是给用户一个折扣+"Free Shipping"。但是,总数不匹配,这可能会让用户感到困惑,因为运费仍显示为已收费。
有没有办法根据这些条件手动将虚拟 "Free Shipping Applied -£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;
}
想出如何解决这个问题。我手动添加了 3.00 美元的 woocommerce_cart_calculate_fee
,然后从总额中减去这个作为 "negative 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;
}
}