• thedeverlopersagency

    (@thedeverlopersagency)


    Hi all,

    I’m trying to add an additional checkout field to the billing and shipping forms. I’m using the Checkout Fields block to output the fields to my template.

    I’ve been able to add my field with woocommerce_register_additional_checkout_field function following the Cart and Checkout – Additional checkout fields.

    Now all I need to do is to place the field in the proper order: the new field is a House number field that should be positioned next to the Address field. However, I’m not able to find how to change the order and add the additonal field between the already existing fields.

    I’ve added my code below:

    add_action('woocommerce_init', function () {
    woocommerce_register_additional_checkout_field(
    [
    'id' => 'tda/houseNumber',
    'label' => __('House Number', 'tda'),
    'optionalLabel' => __('House Number (optional)', 'tda'),
    'type' => 'text',
    'location' => 'address',
    'required' => true,
    'attributes' => [
    'autocomplete' => 'house-number',
    'aria-label' => __('House Number', 'tda'),
    'pattern' => '[A-Z0-9]{5}', // A 5-character string of capital letters and numbers.
    'title' => __('House Number', 'tda'),
    'data-custom' => 'custom data',
    ],
    'sanitize_callback' => function ($field_value) {
    return sanitize_text_field($field_value);
    },
    'validate_callback' => function ($field_value) {
    return is_numeric($field_value);
    }
    ],
    );
    });

    In summary: how can I change the order of the checkout fields while using the WC Checkout Fields block?

    I’m using the following versions:

    • WP 6.7
    • WooCommerce 9.3.3

    Thanks in advance for your time.

    With kind regards,
    Emiel – The Developer’s Agency

Viewing 1 replies (of 1 total)
  • Plugin Support ckadenge (woo-hc)

    (@ckadenge)

    Hi @thedeverlopersagency,

    Helping out with custom coding of this nature is outside the scope of support that our support staff can help out with here, although I would recommend the following:

    1. Running the exact question you’re asking, along with the code provided, through an AI platform like ChatGPT for recommendations/changes to your code;
    2. Checking whether there are existing plugins in the WordPress plugin repository that might be doing that already.
    3. Joining our WooCommerce Slack community (it does have a developer channel where you can ask coding questions): https://woo.com/community-slack/

    Hope it helps!

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.