Hi all I'm kind of new to WordPress. I have created an override for WooCommerce and I'm trying to echo a DOM element with an Advanced Custom Field in it.
I've used this code.
<?php
if (the_field('price_per_unit'))
{
echo '<span class="unit-price">Price per unit: ' . the_field('price_per_unit') . '</span>';
}
echo '<p>Test</p>';
?>
The custom field arrives, so I know I'm in the right file, but the <p>
does not and the word "Test" does not.
Can anyone explain why this happens and how I can get my DOM elements to appear?
I thought it might be some kind of a sanitiser to I tried echoing just the word without any HTML but that also didn't work.
Many thanks
Hi all I'm kind of new to WordPress. I have created an override for WooCommerce and I'm trying to echo a DOM element with an Advanced Custom Field in it.
I've used this code.
<?php
if (the_field('price_per_unit'))
{
echo '<span class="unit-price">Price per unit: ' . the_field('price_per_unit') . '</span>';
}
echo '<p>Test</p>';
?>
The custom field arrives, so I know I'm in the right file, but the <p>
does not and the word "Test" does not.
Can anyone explain why this happens and how I can get my DOM elements to appear?
I thought it might be some kind of a sanitiser to I tried echoing just the word without any HTML but that also didn't work.
Many thanks
Share Improve this question asked Jul 30, 2020 at 13:46 EoinEoin 1156 bronze badges1 Answer
Reset to default 1Thats odd - it works ok here if I simulate this as a text field but other field types may cause a problem.
Try replacing 'the_field()' with 'get_field()' in your code.
If that doesn't work - how is your field setup? Text, Number, Date etc...