Wordpress WooCommerce programmatically set EU VAT when creating an order in PHP
I am really struggling and I really hope that you can help me with this questions.
So the question I am struggling with is:
How can I add the EU VAT with a checkmark in the order? Currently I only get a big red cross in the EU VAT column in the wordpress dashboard. What am I missing?
Screenshot of the order with a big red cross (Check the fifth column)
The code
I made an endpoint in PHP and call it in the frontend. I left some variables out to make it easier to read. You can still see which methods I am calling.
$order = wc_create_order();
$order-add_product($product, $quantity);
$order-set_address($billingAddress,'billing');
$order-set_address($shippingAddress,'shipping');
$country_code = $order-get_shipping_country();
// Set the array for tax calculations
$calculate_tax_for = array(
'country' = $country_code,
'state' = '', // Can be set (optional)
'postcode' = '', // Can be set (optional)
'city' = '', // Can be set (optional)
);
// Get a new instance of the WC_Order_Item_Shipping Object
$item = new WC_Order_Item_Shipping();
$item-set_method_title($shipping_label);
$item-set_method_id($shipping_id); // set an existing Shipping method rate ID
$item-set_total($new_ship_price); // (optional)
$item-calculate_taxes($calculate_tax_for);
$order-add_item($item);
// $order-update_status('on-hold');
$order-calculate_totals();
$order-save();
Thank you for your help!
Topic woocommerce-offtopic plugins Wordpress
Category Web