I am using a custom packing slip / invoice template which will be sent to customers who order through Amazon. The default Amazon shipping method that comes through is: ‘Std UK Dom_1’
I would like to change that so it states ‘Royal Mail’ in its place. I’ve gone in to the php of the template to try and mess around to get it to work myself but it is not quite working how I would like. I was thinking for some kind of IF statement to say something like if the label equals ‘Std UK Dom_1’ then display ‘Royal Mail’ but I am really not sure if that is possible or what format it would be in at all.
The data that is showing the ‘Std UK Dom_1’ is <th class="description"><?php echo $total['label']; ?>
I’m new to this kind of thing so anything that anyone could help with would be great.
<td class="no-borders" colspan="3">
<table class="totals">
<tfoot>
<?php foreach ( $this->get_woocommerce_totals() as $key => $total ) : ?>
<tr class="<?php echo $key; ?>">
<th class="description"><?php echo $total['label']; ?></th>
<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
</tr>
<?php endforeach; ?>
</tfoot>
</table>
</td>
2
Answers
This should do the thing:
$total['label'] === 'Std UK Dom_1'
checks if the label is "Std UK Dom_1".If it is, it returns "Royal Mail".
Otherwise, it returns the label saved in the variable
$total['label']
.The basic construction of this conditional (ternary) operator is:
condition ? exprIfTrue : exprIfFalse;
you can check your data using $total[‘label’] == ‘Std UK Dom_1’ this condition if your condition is true then pass data which you want.
please check below code
== Operator is used to check the given values are equal or not. If yes, it returns true, otherwise it returns false. === Operator is used to check the given values and its data type are equal or not. If yes, then it returns true, otherwise it returns false.