skip to Main Content

I use following array and need to assign a css class selector to the first value of array, but output displays HTML markup too!

woocommerce_form_field(
    $field_id, 
    array(
        'type'          => 'radio',
        'class'         => array('form-row-wide'),
        'options'       => array(
            'alert' => ' <p class="alert">Please allow 2-5 business days for delivery after order processing.</p> ',
            jdate(('d F Y'), $twoDaysAfterTomorrow ) => jdate((' l ، j F Y  '), $twoDaysAfterTomorrow ),
        )
    )
);

However this is showing unrendered radio label text like:

<p class="alert">Please allow 2-5 business days for delivery after order processing.</p>

How is it possible to use HTML tags within field label text and have the markup rendered on the webpage?

2

Answers


  1. Use " for inner quotes. https://3v4l.org/DkHT1

    Login or Signup to reply.
  2. You are fighting again the native behavior of the code.

    See https://woocommerce.github.io/code-reference/files/woocommerce-includes-wc-template-functions.html#source-view.2668

    esc_html( $option_text );
    

    This means that no matter what string you pass into that radio markup building function, the label’s text will be html encode to keep your site safe.

    If you need to find a solution, then perhaps you could try to override/overwrite that function (not recommended), or write a new function that delivers the desired output without html encoding the text, or just manually create the desired output if this is a solitary use case.

    I do not use WP, so I will not be providing a ready-made solution. I suspect that you will be able to engineer your own solution based on the linked source code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search