2017-04-19 9 views
0

Wie kann ich die Zeilensumme für die Erstellung von Bestellung in Woo Commerce berechnen, wenn ich Gutscheincode von 20 rs off und und eine Steuer von 6% verwende.So berechnen Sie Zeilensumme in Wocommerce

$order = new WC_Order(); 
$order = wc_create_order($order_data); 

$items = WC()->cart->get_cart(); 

foreach($items as $item => $values) { 
    $product_id = $values['product_id']; 
    $product = wc_get_product($product_id); 
    $quantity = (int)$values['quantity']; 

    $sale_price = $product->get_price(); 
    $final_price = ????? 
    $price_params = array('totals' => array('subtotal' => $sale_price, 'total' => $final_price)); 
    $order->add_product($product, $quantity,$price_params); 
} 

Hier, wie bekomme ich $ final_price ??

+0

Mit WC_Cart :: calculate_totals(); –

Antwort

0

ich glaube, Sie so etwas wie dieses

$order = new WC_Order(); 
$order = wc_create_order($order_data); 

$items = WC()->cart->get_cart(); 

foreach($items as $item => $values) { 
    $product_id = $values['product_id']; 
    $product = wc_get_product($product_id); 
    $quantity = (int)$values['quantity']; 

    $sale_price = $product->get_price(); 
    $final_price = ????? 
    $price_params = array('totals' => array('subtotal' => $sale_price, 'total' => $final_price)); 
    $order->add_product($product, $quantity,$price_params); 
} 
$order_total=WC()->cart->calculate_totals(); 
+0

Ja, ich habe dies hinzugefügt, aber wenn ich Admin einchecken kann, wird kein Rabattpreis hinzugefügt. Und Rabatt-Coupon, wenn angewendet gilt es für jede Produktwerbebuchung ... so müssen wir das Produkt mit Argumenten hinzufügen .. – parikhdeeshit

+0

U Discount-Typ mit festen Warenkorb Rabatt im Coupon-Abschnitt in woocommerce Einstellung festlegen können. –

+0

Ich habe den Warenkorb Rabatt hinzugefügt, aber wenn ich Bestellung erstelle habe ich Rabatt von 20 Rs für ganze Wagen und 6% Steuern. und Produktpreis ist 50 Rs. Wie kann ich den Endpreis für dieses Produkt bekommen? – parikhdeeshit

0

versuchen dieses tun konnte

public function get_line_total($item, $inc_tax = false, $round = true) { 
    $total = 0; 

    if (is_callable(array($item, 'get_total'))) { 
     // Check if we need to add line tax to the line total. 
     $total = $inc_tax ? $item->get_total() + $item->get_total_tax() : $item->get_total(); 

     // Check if we need to round. 
     $total = $round ? round($total, wc_get_price_decimals()) : $total; 
    } 

    return apply_filters('woocommerce_order_amount_line_total', $total, $this, $item, $inc_tax, $round); 
    }