I discovered I can use the following if there is only one item in my order, however if there are multiple items it replaces the result with the word “Array”. How do I fix this?
// Add VAT onto individual item cost to generate individual item gross value including VAT
function price_inc_vat($cost, $vat) {
$incvat=$cost+$vat;
return "$incvat";
}
I call it using: [price_inc_vat({Item Cost},{Item Tax})], do I need to put a foreach in there somewhere?
-
This reply was modified 5 years, 5 months ago by
coatsy35.
Hi @coatsy35,
I just posted an example snippet in your other thread that should be helpful: https://wordpress.org/support/topic/number-addition/#post-13728054. Basically if there are multiple items then the cost and tax elements will be an array, if there’s a single time then they’ll be strings.
Thanks, that response above of mine was meant to be in the other thread!
For this thread, how do you get it to print the elements name instead of the tag? i.e. {Billing Company} in a function as per my question above?
Hey @coatsy35,
My apologies for the confusion. You need to pass the elements to the function in order for it to be able to return them. For example:
[is_element_empty({Billing Company},{Billing First Name},{Billing Last Name})]
Then the code would look like this (note: untested example):
function is_element_empty( $company, $first, $last ) {
if(empty($company)) {
return $first . ' ' . $last;
} else {
return $company;
}
}
Hi @coatsy35,
I’m marking this as resolved since we haven’t heard back. Let us know if you still have questions about this.
Anyone else, please open a new topic.