1

I'd like to add an anchor link below the Country Dropdown in Woocommerce checkout fields.

I use the code below, but unfortunately without the desired result

add_action( 'woocommerce_form_field_text','additional_paragraph_after_billing_country', 10, 4 );
function additional_paragraph_after_billing_country( $field, $key, $args, $value ){
    if ( is_checkout() && $key == 'billing_country' ) {
        $field .= '<p class="form-row sf_add hide-on-desktop hide-on-tablet"><a href="#SF">extra paragraph here</a></p>';
    }
    return $field;
}

Image for illustration:

enter image description here


Any advice would be appreciated

7uc1f3r
  • 28,449
  • 17
  • 32
  • 50
Ree
  • 259
  • 1
  • 4
  • 16

1 Answers1

2

If you want to add additional paragraph under a country field, you should use the woocommerce_form_field_country hook opposite woocommerce_form_field_text

More explanation can be found in: How should I change the woocommerce_form_field HTML Structure?

So you get:

function filter_woocommerce_form_field_country( $field, $key, $args, $value ) {
    // Compare
    if ( is_checkout() && $key === 'billing_country' ) {
        $field .= '<p class="form-row sf_add hide-on-desktop hide-on-tablet"><a href="#SF">extra paragraph here</a></p>';
    }
    
    return $field;
} 
add_filter( 'woocommerce_form_field_country', 'filter_woocommerce_form_field_country', 10, 4 );
7uc1f3r
  • 28,449
  • 17
  • 32
  • 50