I’m trying to move customer order notes field to another field group, but because of other plugin overrides, I need to override WooCommerce template files too, so I need to move this code:
foreach ( $checkout->get_checkout_fields( 'order' ) as $key => $field ) :
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
endforeach;
from: “mytheme/woocommerce/checkout/form-shipping.php“
to: “mytheme/woocommerce/checkout/review-order.php“.
Now I’m getting duplicated fields, how to prevent duplicates within foreach loop?
2
Answers
You can maintain an
array
to keep track of fields you’ve already seen so that they don’t get added again.Reference page for in_array: PHP in_array
You can use array_unique()
your code will look like this: