【发布时间】: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