我正在尝试在短代码中显示 woocommerce 自定义购物车总金额。该代码获取购物车总计,然后减去“葬礼类型新”类别中任何产品的价格以显示小计。这是代码:
add_shortcode( 'quote-total', 'quote_total' );
function quote_total(){
$total = $woocommerce->cart->total;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
if ( has_term( 'funeral-types-new', 'product_cat', $_product->id) ) {
$disbursement = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
}
}
$subtotal = $total-$disbursement;
echo '<div>'.$subtotal.'</div><div> + '.$disbursement.'</div>';
}
$disbursement 显示正常,但 $subtotal 显示 0,所以我认为 $subtotal = $total-$disbursement; 部分可能有问题?
非常感谢任何帮助。
猛跑小猪
智慧大石