2014-06-12 48 views
2

我希望所有用戶購物車出現在用戶會話中。 Woocommerce使用用戶元來存儲持久性購物車,關鍵是_woocommerce_persistent_car。我能夠使用這個元件獲得用戶手推車。但是我沒有每個用戶的購物車ID。現在的問題是,如果我有這個購物車和它的數據。我想計算包含稅和其他價格的購物車總額。我得到這個結果對於特定的購物車Woocommerce獲取所有用戶的購物車

array (size=2) 
    '28d2995df7158f576605fc9df89a9b4b' => 
    array (size=8) 
     'product_id' => int 344820 
     'variation_id' => int 344868 
     'variation' => 
     array (size=1) 
      'Type' => string '539' (length=3) 
     'quantity' => int 1 
     'line_total' => float 12.99 
     'line_tax' => int 0 
     'line_subtotal' => float 12.99 
     'line_subtotal_tax' => int 0 
    '60f85b840756b7f2e2da48ad8429ca7a' => 
    array (size=8) 
     'product_id' => int 344820 
     'variation_id' => int 344877 
     'variation' => 
     array (size=1) 
      'Type' => string '539' (length=3) 
     'quantity' => int 3 
     'line_total' => float 38.97 
     'line_tax' => int 0 
     'line_subtotal' => float 38.97 
     'line_subtotal_tax' => int 0 

從看到這個結果,我有所有關於車的細節,但是當我在車的總金額計算,我很困惑如何計算的。

任何人都可以幫我計算購物車的總數嗎?

回答

2

如果您有以下數據,您可以使用此代碼獲得總稅和稅。

$total = 0; 
foreach($your_array as $data){ 
    if($data["line_subtotal"]) 
     $total = $total + $data["line_subtotal"]; 

    if($data["line_subtotal_tax"]) 
     $total = $total + $data["line_subtotal_tax"]; 
} 

如果你不想加稅,那麼你可以跳過稅收增加。