Aleš Sýkora / January 9, 2024 / 0 comments

Get WooCommerce Checkout fields slugs

Post summary: Knowing checkout field slugs is crucial for customizing and optimizing your checkout process. It’s like having a secret key to unlock the full potential of your e-commerce site.

If you’ve ever felt like a detective when looking for slug of some field in WordPress and WooCommerce you’re in the right place! Today, you will learn, how to get slugs of WooCommerce checkout fields.

Reveal WooCommerce Checkout fields slugs with PHP

You don’t need to be a tech wizard to uncover these slugs. With some simple PHP you can do it fast.

add_action( 'woocommerce_review_order_before_payment', 'list_all_checkout_fields' );

function list_all_checkout_fields() {
    $checkout_fields = WC()->checkout()->get_checkout_fields();

    foreach ( $checkout_fields as $fieldset_key => $fieldset ) {
        echo '<h3>' . esc_html( $fieldset_key ) . ' Fields</h3>';
        foreach ( $fieldset as $field_key => $field ) {
            echo '<p>' . esc_html( $field_key ) . '</p>';
        }
    }
}

Just add this snippet to your theme’s functions.php file, and go to the checkout page to see the magic. Also, you can use the code snippet plugins.

What Will You Find?

You’ll see a list of all the field slugs used at checkout page – from billing to shipping and beyond. It’s like having a map to navigate the world of Checkout fields.

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

0 comments

Share Your Thoughts