I'm trying to add some markup to a string before assigning it to a variable in PHP.
Wordpress/Woocomerce uses a system of "Hooks" to alter the default behaviour. In this case I'm trying to assign a new label to a text field. I currently have:
<?php
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_phone']['label'] = 'My New Label';
return $fields;
}
?>
Which works fine to set the text to My New Label
, however what I actually want to do is style part of the label using HTML/CSS ( for example have it read "My New Label") so I need to escape the PHP, but nothing seems to be working.
I have tried:
$fields['billing']['billing_phone']['label'] = 'My New' ?> <em> <?php .='Label'?></em><?php;
I have also tried:
$fields['billing']['billing_phone']['label'] = echo "My New <em>Label</em>";
And:
$fields['billing']['billing_phone']['label'] = echo 'My New <em>Label</em>';
Out of desperation I have even tried:
$fields['billing']['billing_phone']['label'] = 'My New ?> <em> <?php Label ?></em><?php';
What am I missing?? There must be a way to do this!
Why are you hopping out of PHP mode? There's no reason for such a badly unreadable statement. Why not just
$foo = 'My new <em>Label</em>';
?
As well, you need to RTM about echo. It's not a function. It has no return value. You cannot ever use it the way you're trying.