1

I have added a custom subscribe field to the WooCommerce comment form. However, right now the field is above everything else. I am not sure how to move it to the bottom below the other fields.

The following code adds the field above everything when user is logged in or logged out.

add_filter( 'comment_form_fields', function( $fields ) {
    echo '<div class="checkbox-wrapper"><input type="checkbox" id="subscribe" tabindex="0" class="hidden"><label for="subscribe" class="visible checkbox">Subscribe to our E-Newsletter</label></div>';
    return $fields;
} );

logged in formlogged out form

I first tried the code below, where it adds the subscribe checkbox at the right position for logged out users. However, the subscribe button is above everything else for the logged in user.

add_action( 'comment_form_logged_in_after', 'additional_fields' );
add_action( 'comment_form_after_fields', 'additional_fields' );
function additional_fields () {
    echo '<div class="checkbox-wrapper"><input type="checkbox" id="subscribe" tabindex="0" class="hidden"><label for="subscribe" class="visible checkbox">Subscribe to our E-Newsletter</label></div>';
}

I have also looked at the following page for possible hook positions but it doesn't seem like it's possible to move the field to just above the submit button.

http://wpengineer.com/2205/comment-form-hooks-visualized/

Any thoughts? Is JavaScript the only option?

0

You should return the div element as a variable, like

$subscribe = '<div>...</div>'; return $subscribe;

By doing echo function, the output is sometimes on top.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.