calculate_totals()
18th January 2021
0 Comments
Framework / CMS
WooCommerce [Version: Since 2.2.0]
Syntax
Typical Usage
Calculate totals by looking at the contents of the WooCommerce order. Stores the totals and returns the order’s final total.
Accepted Parameters
- with_taxes (boolean) (Optional) (Default = true): Whether or not to calculate taxes.
Return Value(s)
Returns a float value of the total cart value of the order.Examples of calculate_totals()
Example 1
<?php
$user_id = get_current_user_id();
$args = array(
'customer_id' => $user_id
);
$new_order = wc_create_order($args);
$new_order->add_product( wc_get_product(1234), 4);
$new_order->calculate_totals();
Used In Projects
Source
https://woocommerce.github.io/code-reference/classes/WC-Abstract-Order.html#method_calculate_totalsWas This Helpful?
If this post has helped you, please let me know. Your feedback will be highly appreciated and will help me build better content.